Adding the anyhow crate to a blank Rust project and running the following code gives you the output Error: error, which I want:
use anyhow::anyhow;
fn error() -> anyhow::Result<()> {
Err(anyhow!("error"))
}
fn main() -> anyhow::Result<()> {
error()
}
However, running the following code only outputs error:
use anyhow::anyhow;
fn error() -> anyhow::Result<()> {
Err(anyhow!("error"))
}
fn main() {
if let Err(error) = error() {
println!("{:?}", error);
}
}
I also tried using "{}" instead, but that also only lead to error being printed.
The documentation says the following:
The Debug format “{:?}” includes your backtrace if one was captured. Note that this is the representation you get by default if you return an error from
fn maininstead of printing it explicitly yourself.Error: Failed to read instrs from ./path/to/instrs.json Caused by: No such file or directory (os error 2)
I couldn't find the part of the source code that added the extra Error: , otherwise I could probably figure it out by myself.