You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EDIT After thinking about it some more, I feel it would be better to improve this error message rather than add API surface area. #1544 gets close, but I believe those errors are still too opaque for Cargo's purposes, and it's hidden behind a flag. Anyway, my original post:
"data did not match any variant of untagged enum {}",
Is there a good way to customize the error message but keep the default #[derive(Deserialize)] implementation? Perhaps a new attribute?:
#[serde(untagged, expecting = "a number or a list of strings")]enumMyEnum{
...
}
Advantages:
You don't have to reimplement Deserialize
Concise
Disadvantages
How common is this use-case? We have to do this a couple of times within Cargo.
Is there a better solution I am overlooking?
The text was updated successfully, but these errors were encountered:
yaymukund
changed the title
Idea: Provide an easy way to customize only the error message
Provide an easy way to customize only the error message
Sep 2, 2020
Use serde's error message option to avoid implementing `Deserialize`.
This is a cleanup based on serde-rs/serde#1883, which fell out of #8664
It looks like this changes the resulting error messages. I'll leave it up to you to decide if the tradeoff makes sense here. Maybe the correct answer here is to make `serde`'s error messages include more details (e.g. `invalid type: int`).
EDIT After thinking about it some more, I feel it would be better to improve this error message rather than add API surface area. #1544 gets close, but I believe those errors are still too opaque for Cargo's purposes, and it's hidden behind a flag. Anyway, my original post:
I have an untagged union:
If all variants fail, you get this error message:
serde/serde_derive/src/de.rs
Line 1648 in 9f331cc
Is there a good way to customize the error message but keep the default
#[derive(Deserialize)]
implementation? Perhaps a new attribute?:Advantages:
Deserialize
Disadvantages
The text was updated successfully, but these errors were encountered: