Untyped nil and nil containers are handled inconsistently across the API
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 20/100
Research direction
Start with the single-key Get and Array.Get in node.go (around lines 234-249), which already normalise untyped nil to Nil, and compare them with Find, multi-key Get/Has, Merge, Walk and the array growth in edit. The maintainers still need to pick the 1.0 rule for Array(nil) and Map(nil) before a patch can be written. Done means one agreed rule, applied across those paths, with a test for each case in the table.
Written by the indexing model from the issue text.
Description
Problem
The library normalises an untyped Go nil to Nil (NilValue) at its entry points, but not elsewhere. Callers can therefore receive a raw nil Node or hit a panic depending on which API they use.
Normalised today (nil / missing → Nil):
- single-key
Map.Get/Array.Get(https://github.com/mojatter/tree/blob/622a9ee87cc319f8cbc105ea5f5cefb124f25edf/node.go#L234-L249) ToValue(nil),V(nil),ToNode(nil)- JSON / YAML
nullon decode Node.Value()on a mismatched type
Not normalised:
| Case | Current behaviour |
|---|---|
Find(Array{nil}, ".[0]"), ".[]" |
returns []Node{nil} (raw nil leaks) |
Map{"a": nil}.Get("a", "b"), Has("a", "b") |
panic (method call on nil interface) |
Find(nil, ".") |
panic |
Merge(nil, x), Merge(x, nil) |
panic |
Merge(Map(nil), Map{...}) |
panic (assignment to nil map) |
Walk over Map{"a": nil} |
nil children silently skipped |
Edit(".a[2] = 1") on {"a": []} |
creates Array{nil, nil, 1} holes |
Array(nil) / Map(nil) add a second flavour: JSON encodes them as null, YAML as [] / {}, and ToNode / ToAny / Clone turn them into empty non-nil containers.
Proposed direction
Pick one rule for 1.0 — likely "never hand out an untyped nil Node; treat it as Nil on read" — and apply it to Find / query Exec, multi-key Get / Has, Merge, Walk and the array growth in edit (fill holes with Nil). Decide separately whether Array(nil) / Map(nil) should encode as null or as empty containers.
Clone / CloneDeep already return Nil for an untyped nil as part of #102.
- Dominant language
- Go
- Stars
- 7
- Forks
- 2
- Avg merge
- 11h 12m
- Merged PRs (30d)
- 43
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mojatter/tree
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
bug
Difficulty 3/5 1-2 days Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
query: Read null like jq in key steps, comparisons and contains()Possibly taken @mojatter claimed this 1 day ago. Openbug
Difficulty 4/5 3-5 days Newbie friendliness 55/100
mojatter/tree#152 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
[flaky test] TestValidatorCommitterDropsEmptyStatusBatch: submits to the mock VC before its stream is registeredPossibly taken @liran-funaro claimed this today. Opencoordinator flaky-test race-condition testing
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
hyperledger/fabric-x-committer#876 ·
Maintainers usually reply within 1 day
-
kind/features
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
TencentBlueKing/bk-nodemgr#3804 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cloudnative-pg/plugin-barman-cloud#1187 ·
Maintainers usually reply within 1 day
-
[deliverclient] Remove the unused common/deliverclient packagePossibly taken @liran-funaro claimed this today. Opencode-hygiene
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
hyperledger/fabric-x-common#236 ·
Maintainers usually reply within 1 day
-
consensus feature I2 S4 U2
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day