Skip to content

Display for Report only includes the latest wrap_err #234

@emilk

Description

@emilk

Problem

Consider this code:

    let err = eyre::format_err!("root_cause")
        .wrap_err("inner_context")
        .wrap_err("outer_context");

    assert_eq!(err.to_string(), "outer_context"); // Oh no, we don't see the root cause!

This is a very common and big footgun when printing errors: most of the error message is discarded.

In particular, if you write log::error!("A problem occurred: {err}") then two months later you get an error report from a user, and you realize the most important part of the error message (the root cause) is missing.

Suggested solution

Change Display for Report to print the whole chain, e.g. the above would print "outer_context -> inner_context -> root_cause".

Alternative

I can see that this would be controversial though, so an alternative is to remove the impl Display for Report and force users to pick between:

  • report.chain()
  • report.root_cause()
  • report.outer() (a proposed new method returning the outermost message)

All the above would return types that implement Display.

Other alternatives

I don't know.

Can I somehow get clippy to help me catch these foot guns?

Related

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