-
Notifications
You must be signed in to change notification settings - Fork 84
Closed
Description
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
anyhow
has the same problem: It doesn't print the whole chain, only the last context dtolnay/anyhow#85
JonasWanke
Metadata
Metadata
Assignees
Labels
No labels