BurntSushi / BurntSushi/rust-csv
Serde Deserialize errors do not set the field index
- Dominant language
- Rust
- Stars
- 2k
- Forks
- 257
- PR merge metrics
- No merged PRs in 30d
Description
A field that returns a serde deserialize error will always have the `field` set to `None`.
```rust
impl SerdeError for DeserializeError {
fn custom(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
```rust
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.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.