Skip to content

How to get meaningful parsing error messages that include input string? #33

Answered by frozenlib
fritzrehde asked this question in Q&A
Discussion options

You must be logged in to vote

At present, parse_display lacks the functionality to produce meaningful error messages.

I've personally faced scenarios where I wanted error messages to incorporate input strings, and would like to improve this.

However, it appears to be a common practice in Rust not to include input strings in errors.
This is the case for errors included in the standard library (e.g. std::num::ParseIntError), url crate (e.g. url::ParseError), and chrono crate (e.g. chrono::format::ParseError).

If an error contains an input string, String must be created from the input &str and included in the error, which is a performance disadvantage.
So, I believe this practice is appropriate.

For example, when parsing…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@fritzrehde
Comment options

Answer selected by fritzrehde
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants