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

Implementation of Display for Error displays the source of the error, not the error message #61

Open
SabrinaJewson opened this issue Mar 6, 2022 · 0 comments

Comments

@SabrinaJewson
Copy link

The current implementation of Display for Error forwards to the inner type's implementation of Display if there is one. However, it is preferable not to do this, for two reasons:

  1. if the user wants the string representation of the inner error, they can always call .source()?.to_string() instead.
  2. When formatted with tools such as Anyhow, the error message ends up duplicating the same information twice, e.g.:
Error: failed to refresh syndication feeds

Caused by:
0: incomplete utf-8 byte sequence from index 5
1: incomplete utf-8 byte sequence from index 5

It would be better if the error displayed what went wrong instead of why it went wrong, producing more helpful traces like this:

Error: failed to refresh syndication feeds

Caused by:
0: failed to parse Atom feed
1: incomplete utf-8 byte sequence from index 5

Now the error message tells a very clear and unambiguous story of exactly what happened. It makes it much easier to debug and is more friendly for users.

Note that this applies even to variants other than Error::Utf8 and Error::Xml. For example, the trace of an Error::Eof would better look like this:

Error: failed to refresh syndication feeds

Caused by:
0: failed to parse Atom feed
1: unexpected end of input

Than what it currently looks like:

Error: failed to refresh syndication feeds

Caused by:
0: unexpected end of input

What had an unexpected end of input? The error doesn't tell you.

The improved trace can be implemented by having source() return a new (potentially private) type EofError which Displays as "unexpected end of input".

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

No branches or pull requests

1 participant