stacks-network / stacks-network/stacks-core

[clarity] `var-get` of non existing data var returns `none` instead of throwing

Open
#5,166 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
3.1k
Forks
762
Avg merge
4d 6h
Merged PRs (30d)
76

Description

According to the docs, a var-get of a not-yet-existing var should throw an error; instead, it seems to be returning none:

clarity-repl v2.8.0
Enter "::help" for usage hints.
Connected to a transient in-memory database.
>> ::advance_chain_tip 1
1 blocks simulated, new height: 1
>> (define-data-var data int 1)
(define-public (foo (block uint)) (ok (at-block (unwrap-panic (get-block-info? id-header-hash block)) (var-get data))))
→ .ST000000000000000000002AMW42H.contract-0 contract successfully stored. Use (contract-call? ...) for invoking the public functions:
>> ::advance_chain_tip 1
1 blocks simulated, new height: 2
>> (contract-call? .contract-0 foo u1)
(ok 1)
>> (contract-call? .contract-0 foo u0)
(ok none)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior in clarity-repl using the documented var-get and at-block example from the issue, comparing a not-yet-existing variable with the existing-variable case. Trace the var-get execution path to determine why the missing value returns none; done means the documented missing-variable behavior is restored and covered by a regression check.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
blockchain
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.