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

Add Option to make Unmarshal() return an error if parsed data contains unprocessed keys #277

Closed
fho opened this issue May 9, 2019 · 3 comments
Labels
feature Issue asking for a new feature in go-toml.

Comments

@fho
Copy link

fho commented May 9, 2019

Currently it's impossible to handle when a toml configuration file contains a typo in the name of an optional key.
I can't check if the value in the unmarshalled struct is empty because it's an optional field.
An empty value is valid.

Suggestion:
Add an option for the go-toml Encoder, that if enabled makes Unmarshal() return an error when the passed data contains keys that were not unmarshalled into any fields of the passed struct.

@fho fho changed the title Add Option to make Unmarshal return an error if parsed data contains unprocessed keys Add Option to make Unmarshal() return an error if parsed data contains unprocessed keys May 9, 2019
@pelletier
Copy link
Owner

Sounds good to me! Thank you. Do you happen to know of any other Go encoding/decoding libs that support that feature? If there are existing "standards" for this feature, would love to follow them to match expectations / lower surprises.

@pelletier pelletier added the feature Issue asking for a new feature in go-toml. label May 20, 2019
@fho
Copy link
Author

fho commented May 20, 2019

@pelletier no, sorry I don't know how other decoders solve it

@lmb
Copy link
Contributor

lmb commented Jul 25, 2019

https://godoc.org/github.com/naoina/toml has an option MissingField func(typ reflect.Type, key string) error which is called when no match is found.

github.com/BurntSushi/toml allows accessing undecoded fields after decoding: https://godoc.org/github.com/BurntSushi/toml#ex-package--StrictDecoding

Both work, I think the function is nicer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Issue asking for a new feature in go-toml.
Projects
None yet
Development

No branches or pull requests

3 participants