-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Encoding: 'omitempty' will panic if the struct contains a uncomparable type #360
Comments
Thanks for the reproducible example; this should be fixed by #361: it will return an error now instead. |
Thanks for the fast fix. Is it correct to return an error here? Atleast that would be a breaking change because with 1.1.0 it was possible to encode those structs. Now everyone has to check every struct for compareable types before useing an omitempty flag. |
Wouldn't it be surprising if you add Breaking compatibility of course isn't great, but it seems to me that adding We could ignore it, or maybe add a Strict option or something. I'll reopen this issue for now to discus. |
Would probably be best to see how encoding/{json,xml} behave for this, and then copy that. I typically try to follow the stdlib encoding's lead unless there's a good reason not to, as it avoids confusion. |
Maybe you understood me wrong but I wouldn't ignore it silently. I wanted to say that it should be checked field by field if the struct is uncomparable instead of returning an error. I'm pretty sure the stdlib does it that way. I'm not sure about the best/efficient way to check if a struct is empty. I think the stdlib always compares on a field basis if my understanding of that code is correct. |
…efore This is more compatible with the previous behaviour, as well as what stdlib does. Ref: #360
The standard library doesn't do anything for structs; omitempty on those seems silently ignored (no error). omitempty support for structs was added in the last release of this library. This is the equivalent of So I guess that ignoring it is better. Support for some of these types could be added by looping over all struct fields and recursively calling isEmpty() on them as long as the type isn't a struct. Something like the below seems to work in a quick test, but need to look at it more. For now, I just changed it to silently ignore these fields.
|
Yes of course you are right. They will print out an empty object. Can I contribute anything to help you? |
Sure! Can make a PR based on the above with a bunch of test cases (including deeply nested structs and the like). |
Also see the discussion over here regarding the implementation: #361 (comment) |
I will check that. This week is unfortunately a little bit busy, so I will probably do it next week. |
Sure, don't feel obliged :-) |
See BurntSushi/toml#360 A recent change in BurntSushi/toml made encoding fail (later changed to error) if a struct is marked as omitempty and is comparable. Go docs about equality: https://go.dev/doc/go1#equality. Basically: A struct is comparable if all of its fields are comparable. Slices are not comparable. Customizations are marked as omitempty but they contain a lot of slices, thus they are not comparable. The new version of BurntSushi/toml therefore panics when we encode them. The solution is to remove the omitempty tag from Customizations. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
See BurntSushi/toml#360 A recent change in BurntSushi/toml made encoding fail (later changed to error) if a struct is marked as omitempty and is comparable. Go docs about equality: https://go.dev/doc/go1#equality. Basically: A struct is comparable if all of its fields are comparable. Slices are not comparable. Customizations are marked as omitempty but they contain a lot of slices, thus they are not comparable. The new version of BurntSushi/toml therefore panics when we encode them. The solution is to remove the omitempty tag from Customizations. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
I believe there is an additional issue where In other words: |
Fixed via #366 |
#366 does not appear to address the fact that |
Yes please @joukewitteveen; sorry, I didn't really register your comment back in August as I was busy with other things, and when I fixed this yesterday I just didn't see your comment so I didn't look in to it. It seems mostly unrelated anyway (other than being about the omitempty struct tag); usually best to err on the side of creating new issues for things, especially smaller projects like this where people only work on every once in a while. Just so easy to miss stuff otherwise. |
This fixes an error when processing blueprints with customizations.firewall See BurntSushi/toml#360 for details on the upstream bug.
This fixes an error when processing blueprints with customizations.firewall See BurntSushi/toml#360 for details on the upstream bug.
This fixes an error when processing blueprints with customizations.firewall See BurntSushi/toml#360 for details on the upstream bug.
This fixes an error when processing blueprints with customizations.firewall See BurntSushi/toml#360 for details on the upstream bug.
This fixes an error when processing blueprints with customizations.firewall See BurntSushi/toml#360 for details on the upstream bug.
- BurntSushi/toml#360 is closed in 1.2.1 Signed-off-by: Natalie Arellano <narellano@vmware.com>
This fixes an error when processing blueprints with customizations.firewall See BurntSushi/toml#360 for details on the upstream bug.
This fixes an error when processing blueprints with customizations.firewall See BurntSushi/toml#360 for details on the upstream bug. Resolves: rhbz#2150920
While encoding a struct will be checked for emptiness with the isEmpty function:
The comparing of structs panics if the structs contains any uncomparable type.
Minimal example:
Output:
The text was updated successfully, but these errors were encountered: