BurntSushi / rust-csv

A CSV parser for Rust, with Serde support.
The Unlicense
1.72k stars 219 forks source link

Improve error reporting of the serde csv serializer. #317

Open jstranik opened 1 year ago

jstranik commented 1 year ago

Make the error messages to show also the field and value that failed to serialize.

Example of an error before the change:

Error Parsing Data: CSV deserialize error: record 1 (line: 2, byte: 549): trailing input.

The new improved error message is now displayed as:

Error Parsing Data: CSV deserialize error: record 1 (line: 2, byte: 549): trailing input. (Field 'trade_timestamp' has a value '2023-04-04T09:46:45.000Z')

Notice the field name and field value that caused problem during the import.

schell commented 2 months ago

This would be great. Is there any other way to map an error back to the field that failed to parse?

schell commented 2 months ago

For anyone else following along - you can match on Error::kind(), and the Deserialize variant's err has a field() function that will give you the field index...