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

More helpful errors for mismatched types on struct decoding #628

Closed
samhza opened this issue Oct 14, 2021 · 2 comments
Closed

More helpful errors for mismatched types on struct decoding #628

samhza opened this issue Oct 14, 2021 · 2 comments
Labels
feature Issue asking for a new feature in go-toml. v2 Issues impacting the v2 major version.
Milestone

Comments

@samhza
Copy link

samhza commented Oct 14, 2021

Go's encoding/json's displays errors such as json: cannot unmarshal number into Go struct field Foo.bar of type string.
It would help for go-toml to display similar errors. Currently, the errors are quite vague and make it difficult for users to know where in the config the error is: toml: cannot store TOML integer into a Go string.

@pelletier pelletier added feature Issue asking for a new feature in go-toml. v2 Issues impacting the v2 major version. labels Oct 14, 2021
@pelletier
Copy link
Owner

Sounds good to me!

@pelletier pelletier added this to the v2.0.0-beta.5 milestone Oct 23, 2021
@pelletier pelletier changed the title more helpful errors for mismatched types on struct decoding More helpful errors for mismatched types on struct decoding Nov 10, 2021
pelletier added a commit that referenced this issue Nov 25, 2021
The goal is to provide some context as to why the type were mismatched. This
change only works for that case, on structs. This is the same a encoding/json. A
more general solution would be great, but this would require a broader change in
the decoder, which I don't think is necessary at the moment.

Fixes #628
pelletier added a commit that referenced this issue Nov 25, 2021
The goal is to provide some context as to why the type were mismatched. This
change only works for that case, on structs. This is the same a encoding/json. A
more general solution would be great, but this would require a broader change in
the decoder, which I don't think is necessary at the moment.

Fixes #628
@pelletier
Copy link
Owner

Added that error message as part of #684.

It provides that extra info when facing a type mismatch in a struct field, with a message that looks like:

toml: cannot decode TOML integer into struct field toml_test.mystruct.Bar of type string

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. v2 Issues impacting the v2 major version.
Projects
None yet
Development

No branches or pull requests

2 participants