-
Notifications
You must be signed in to change notification settings - Fork 192
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
error messages don't compose well with anyhow #533
Comments
Thanks for the report @davepacheco! It looks like we need to take a fresh look at our error handling story. If this is something you’re interested in exploring please feel free to dig into it! |
Alrighty, I’ve reworked the internal shape of |
Thanks for doing that! It looks great. If I switch the test repo to use commit 2925da3 (current tip of main), the output looks like this:
which is perfect. Thanks! Any idea when this will wind up in a release on crates.io? |
Describe the bug
I've been using @dtolnay's anyhow crate as a great way to annotate errors with context about was happening when an error was generated. I found that with
uuid
, though, it generates duplicate messages.To Reproduce
Steps to reproduce the behavior:
cargo run
Here's the relevant code:
Expected behavior
I expected this to print:
but it actually prints:
Screenshots
The rest of the program shows exactly what the error chain looks like. Here's the output:
Specifications (please complete the following information):
This is with
uuid
0.8.2,anyhow
1.0.44, rust 1.52.0, on MacOS 11.6 (Big Sur). I haven't enabled any features. (You can see the complete details in the Cargo.toml and Cargo.lock in the repo I linked to.)Additional context
anyhow
uses the alternate Display format to print the whole cause chain as a single message. I like this a lot because it prints errors the way most standard Unix tools do.I believe the way it works is it follows the cause chain using std::error::Error::source() and prints out the message associated with each one. This seems pretty reasonable.
I think the problem is that the uuid crate uses a few levels of Error (i.e., a cause chain), and
Display
on the higher level impl delegates to the next level. So if one walks the cause chain and prints each one out, you get the duplicated message. This structure doesn't really seem right, though I'm not sure the best fix because I'm not sure why the indirection.The text was updated successfully, but these errors were encountered: