-
Notifications
You must be signed in to change notification settings - Fork 72
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
Consider adding helpers for better deserialize error messages for untagged enums #635
Comments
Our `serde_derive` fork for better error messages when deserializing untagged enums does no longer build fine, and troubleshooting that has a significant maintenance cost. Let's drop that patch and explore the better-supported alternative of using custom visitors, preferably after getting some kind of resolution to jonasbb/serde_with#635.
I would love to have support for that, but for now, I do not see a way how I can support that. The problem is that the error messages are generated by the This means, fixing the issue requires forking |
Thanks for your prompt reply!
I have been maintaining such a fork for over a year now, and I would gladly welcome help with that. However, I don't think that forking is a tenable long-term solution. Right now, my fork does not build when third-party crates patch the So far,
For the reasons stated above, I want to focus my efforts on ditch a fork and build a less brittle, long-term solution instead. This means that we have to play by the rules of I gave this angle a try on this Rust Playground snippet, where I managed to replace the default If we were to implement this functionality, what small, likely acceptable by upstream things would we need |
Are you trying to fork serde+serde_derive? That would be more powerful, but I am uncertain if requiring patching the dependency for every user is worth it. I was more thinking or providing a separate crate with new proc-macros, similar to how
I am not sure what you are trying to do in the snippet. Your goal is to replace #[derive(Deserialize, Debug)]
#[serde(untagged, expecting = "cannot parse either `A` or `B` for UntaggedEnum")]
enum UntaggedEnum {
A(u64),
B(String),
} If a different (static) error message is all you want, you can create a proc-macro, that runs before the |
Yes, that's exactly what I did. Your idea of providing custom proc-macros for deriving
With that snippet I was trying to bring forward a general way to improve error messages. The fact that it replaces the error message with a constant string is incidental: the code could easily be modified to display a non-constant string, unlike with the Ideally, I would like
As a result, I suppose this issue boils down to whether it would be nice for |
I do not see a way forward with wrappers that goes beyond a static message. There is no way for wrappers to get any information about why deserialization fails. Not without changing the If you find a way to make the wrappers emit a dynamic message explaining what failed, then I would very much like to see that. serde attributes are indeed not always documented, but |
I understand. I will let you know if I find some way to do it!
That attribute has just been documented moments ago thanks to a PR I submitted 😉 |
As described in #586,
serde
outputs unsatisfactory messages when an error occurs during untagged enum deserialization.Recently, the
serde
project explicitly rejected improving error messages for this situation by collecting deserialization errors, suggesting instead that applications use custom visitors to achieve better diagnostics. Incidentally,serde_with
has been identified as a candidate crate to provide reusable functionality to make it easier to create these kinds of custom visitors.As a result, I'd love to hear if such a feature would be in scope for
serde_with
. In my view, user-facing applications that parse configuration files will benefit most from this feature, as good error messages enable users to more easily troubleshoot and fix their configuration file syntax.The text was updated successfully, but these errors were encountered: