Skip to content

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

Open
@SabrinaJewson

Description

@SabrinaJewson

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".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions