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

[BUG] Dasel crash when reading an empty file #374

Closed
Larandar opened this issue Nov 14, 2023 · 5 comments
Closed

[BUG] Dasel crash when reading an empty file #374

Larandar opened this issue Nov 14, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@Larandar
Copy link

Describe the bug

Dasel will crash if called on an empty file, even if it's by specification in most implementations interpreted as a valid file for that format (yaml and toml).

(Yes, I just read both TOML and YAML specs, and it's ambiguous as in both case an unquoted empty string is corresponding to nil but the lexer seems to assume at least one identifier)

To Reproduce

touch /tmp/bug.toml
dasel -f /tmp/bug.toml

Will fail:

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

goroutine 1 [running]:
reflect.valueInterface({0x0?, 0x0?, 0x0?}, 0x0?)
	reflect/value.go:1495 +0xfc
reflect.Value.Interface(...)
	reflect/value.go:1490
github.com/tomwright/dasel/v2.Value.Interface({{0x0, 0x0, 0x0}, 0x0, 0x0, 0x0})
	github.com/tomwright/dasel/v2/value.go:55 +0x6c
...

Expected behavior

Such files should be handled like most parsers interpreted it, so nil. This way creating a new toml file can be as simple as:

touch /tmp/state.toml
dasel put -f /tmp/toml .state.last-execution -t string -v $(date -Iseconds)

Desktop (please complete the following information):

  • OS: macOS 14.1
  • Version: dasel version 2.4.1
@Larandar Larandar added the bug Something isn't working label Nov 14, 2023
@TomWright
Copy link
Owner

Thanks for highlighting this @Larandar .

Dasel has an issue with nulls at the moment, stemming from the fact that it uses reflection internally. That said, it shouldn't be too hard to get this working. I'll work on this soon.

@TomWright
Copy link
Owner

I think I accidentally broke this by commenting this out:

// todo : check if this is still needed.

I'll try and verify this tonight

@TomWright
Copy link
Owner

This has been fixed in the development release and will be released soon.

@Larandar
Copy link
Author

Ha, the good old "I'm sure this code is not applicable anymore" 👍

@TomWright
Copy link
Owner

Hey @Larandar,

This was included in the last release.

$ dasel -v
dasel version 2.5.0
$ touch empty.toml
$ dasel -f empty.toml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants