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

should serde provide a trait to standardize text position in errors? #1184

Closed
Geal opened this issue Mar 20, 2018 · 3 comments
Closed

should serde provide a trait to standardize text position in errors? #1184

Geal opened this issue Mar 20, 2018 · 3 comments

Comments

@Geal
Copy link

Geal commented Mar 20, 2018

Hello,
For a bit of context, I've added to one of my projects an error display like rustc, but for toml deserialization: https://twitter.com/gcouprie/status/976117416194428930

The code for this is quite simple ( https://github.com/sozu-proxy/sozu/blob/master/command/src/config.rs#L576-L583 ), but I was surprised that there's no common trait to provide position in errors for text formats parsed with serde.

Could we have a trait that those crates could implement, that would provide position information for errors? And possibly, not only as a line and column, but as a span (so we can show "the issue is from here to there")

@dtolnay
Copy link
Member

dtolnay commented Mar 20, 2018

There would need to be a compelling real use case that benefits from having a trait for this.

I would note that just the opportunity for consistency is not enough reason to have a trait. For example Vec and VecDeque and HashMap all have a fn reserve(&mut self, additional: usize) but it doesn't mean there needs to be a trait involved.

@Marwes
Copy link
Contributor

Marwes commented Mar 20, 2018

And possibly, not only as a line and column, but as a span (so we can show "the issue is from here to there")

For this you may want to look at https://github.com/brendanzab/codespan (cc @brendanzab)

@dtolnay
Copy link
Member

dtolnay commented Jun 3, 2018

Closing because I don't think an error position trait would carry its weight, but it would be nice to get the other formats changed to be more consistent with serde_json.

@dtolnay dtolnay closed this as completed Jun 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants