Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the error caused by null elements in array #307

Merged
merged 1 commit into from
Mar 27, 2023

Conversation

semihbkgr
Copy link
Contributor

@semihbkgr semihbkgr commented Mar 27, 2023

fixes #296

It was failing when working on an array which has null elements. It is basically caused by trying to set the reflect.Value of the nil pointer to slice index.

panic: reflect: call of reflect.Value.Set on zero Value

goroutine 1 [running]:
reflect.flag.mustBeExportedSlow(0x1517da0?)
	reflect/value.go:235 +0xc5
reflect.flag.mustBeExported(...)
	reflect/value.go:229
reflect.Value.Set({0x1517da0?, 0xc0002a8620?, 0x7?}, {0x0?, 0x0?, 0xc0002b1790?})
	reflect/value.go:2155 +0x9f
github.com/tomwright/dasel/v2.derefSlice({0x1517da0?, 0xc000267cb0?, 0xc0001f4a20?})
	github.com/tomwright/dasel/v2/value.go:347 +0x1ad
github.com/tomwright/dasel/v2.deref({0x1517da0?, 0xc000267cb0?, 0x0?})
	github.com/tomwright/dasel/v2/value.go:370 +0x65
github.com/tomwright/dasel/v2.derefMap({0x1517da0?, 0xc00025ae60?, 0xc0002b1901?})
	github.com/tomwright/dasel/v2/value.go:359 +0x13d
...

an example of how it works after the changes:

[
  {
    "a": "alice",
    "b": 9,
    "c": [
      null,
      "bob",
      13,
      null,
      9,5,
      null
    ]
  },
  null
]
$ dasel -r json -w yaml -f test.json
- a: alice
  b: 9
  c:
  - null
  - bob
  - 13
  - null
  - 9
  - 5
  - null
- null

@TomWright TomWright merged commit 8dceecd into TomWright:master Mar 27, 2023
@TomWright
Copy link
Owner

Thanks for the contribution 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic when converting JSON null values
2 participants