Attach line & file info to anyhow::Error and anyhow::Context
Author: vultixCreated Feb 5, 2021Updated Dec 11, 2025
First off, thank you for this wonderful library!
Context
It's often difficult to find where in your code an error occurred. Rust's backtraces help with this, but are often so verbose that it's still difficult.
Proposal
It would be great if you could simply glance at the error output to get file and line information. This could be implemented using #[track_caller] and can be optionally turned on using a feature flag.
I'm not sure what format you'll want, but I'm imagining something like this:
Error: Failed to parse file: hello.txt @ main.rs:7:10
Caused by:
0: Unable to convert this string into a float: '1.5a' @ main.rs:19:24
1: invalid float literal @ main.rs:25:32
Stack backtrace:
...I'm willing to make a PR if you like this feature!
Source: dtolnay/anyhow