-
Notifications
You must be signed in to change notification settings - Fork 123
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
Enhancement: better error messages for missing struct fields? #393
Comments
On Err(SpannedError { code: Message("missing field `f2`"), position: Position { line: 4, col: 1 } }) I'll check if we could also give the name of the struct or enum variant where the field is missing |
I think we should make necessary API breaking changes now (if any) and then release master as 0.8, so the new features, especially better errors, become available. |
Ok, so the error message here comes from If we then have such variants, we could populate them with extra optional information that would be @d86leader What I use for such nice contextual error messages is the let mut de_ron = ron::Deserializer::from_str_with_options(ron_str, ron_options)?;
let mut track = serde_path_to_error::Track::new();
let de = serde_path_to_error::Deserializer::new(&mut de_ron, &mut track);
let result = match Test::deserialize(de) {
Ok(args) => Ok(args),
Err(err) => {
let path = track.path();
let err = de_ron.span_error(err);
Err(format!(
"{}{} @ ({}):\n{}",
path,
if path.iter().count() >= 1 { "" } else { "*" },
err.position,
err.code,
))
},
} |
Thanks! I agree, if there is line info, having constructor or type name is not necessarily necessary. I will close this issue then. Can't wait for 0.8, with this and supplying extensions via decoder options! |
@torkleyy Do you think we should convert |
If we can provide better error information without overly cluttering the codebase, absolutely, yes! |
Currently missing fields in struct gives no line info, not even the typename info, which makes it hard to find where in the row of same-y declarations you missed a field. For example:
gives:
Err(Error { code: Message("missing field
f2"), position: Position { line: 0, col: 0 } })
It would be great if I could get line info, or at least the name "Test" of the record.
Also there is a similar problem with enum variants. Which seems doubly strange, as when I write an incorrect constructor for a struct, like replacing "Test" with "NotTest" in the example above, I get precise error location and type info.
The text was updated successfully, but these errors were encountered: