Short backtrace
Opened this issue · 2 comments
I have large codebase which uses anyhow::{Result, Context, bail}
a lot,
and the errors don't tell much. No filename/line numbers at all.
Using RUST_BACKTRACE=1
is not convenient.
I found #22 but it will require many changes to add it everywhere.
Is there an elegant way to get short backtrace when error occur, just like we get it with unwrap()
?
Example:
use anyhow::{Result, bail};
fn main() -> Result<()> {
job()
}
fn job() -> Result<()> {
bail!("error in job")
}
cargo run
Error: error in job
Imagine large codebase with many errors coming from internal libraries... no idea where it happens.
Thanks
You can call .backtrace()
on the error value to get a backtrace you can print if RUST_BACKTRACE=1
or RUST_LIB_BACKTRACE=1
is used.
You can call
.backtrace()
on the error value to get a backtrace you can print ifRUST_BACKTRACE=1
orRUST_LIB_BACKTRACE=1
is used.
it used Rust std::backtrace, so there is no direct access to frames, only std::fmt::Debug which is verbose