Skip to content
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

Serde Deserialize errors do not set the field index #385

Open
RossWilliams opened this issue Feb 26, 2025 · 0 comments · May be fixed by #389
Open

Serde Deserialize errors do not set the field index #385

RossWilliams opened this issue Feb 26, 2025 · 0 comments · May be fixed by #389

Comments

@RossWilliams
Copy link

A field that returns a serde deserialize error will always have the field set to None.

impl SerdeError for DeserializeError {
    fn custom<T: fmt::Display>(msg: T) -> DeserializeError {
        DeserializeError { field: None, kind: DEK::Message(msg.to_string()) }
    }
}

It does not appear we can determine the field that failed to deserialize from serde to report to the user.

One option is to modify the deserialize_string_record function to manually set the err.field in the map_err closure

D::deserialize(&mut deser).map_err(|mut err| {
        err.set_field(Some(deser.0.field.saturating_sub(1));
        Error::new(ErrorKind::Deserialize {
            pos: record.position().map(Clone::clone),
            err,
        })
    })

I am unsure if this is a valid solution or if there are edge cases that will cause the field index to not be accurate.

@RossWilliams RossWilliams linked a pull request Mar 1, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant