anyhow icon indicating copy to clipboard operation
anyhow copied to clipboard

Short backtrace

Open thewh1teagle opened this issue 2 years ago • 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 https://github.com/dtolnay/anyhow/issues/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

thewh1teagle avatar Apr 21 '24 00:04 thewh1teagle

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.

bjorn3 avatar Jun 19 '24 17:06 bjorn3

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.

it used Rust std::backtrace, so there is no direct access to frames, only std::fmt::Debug which is verbose

0x241F31 avatar Jul 08 '24 18:07 0x241F31