-
-
Notifications
You must be signed in to change notification settings - Fork 531
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
When two struct fields have the same tag, a matching TOML value is silently ignored #384
Comments
encoding/json seems to set only the first one:
Outputs:
I guess that's better? Personally I think both are confusing and I'd prefer to return an error, but usually I try to follow the behaviour of encoding/json. |
@arp242 I think a returned error would be completely reasonable... in our case the declaration of the struct tag was a mistake/bug. We copied and pasted from the line above and failed to update the toml tag on the copy - an error would've meant we'd catch the bug prior to deploy to our development environment. Following JSON's approach would mean nothing previously working would be broken, but the new config value would be ignored. (A better spot to be in than the one we experienced where the old value also stopped working, and we had to figure out why.) |
I agree; but on the other hand being a drop-in replacement for encoding/json – warts and all – also has some value. It's not uncommon to (un)marshal the same struct from multiple formats (TOML, JSON, YAML, etc.) A second concern is that changing the behaviour is essentially backwards-incompatible, and that it might break "accidentally works" types of scenarios. I have no idea if it'll break for one person, 10 people, or hundreds of people. |
PoC code:
Output:
Expected output:
Or... an error returned from the Decode function (this would've been preferable for our case, where this was a typo.)
The text was updated successfully, but these errors were encountered: