Skip to content
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

Short backtrace #362

Open
thewh1teagle opened this issue Apr 21, 2024 · 2 comments
Open

Short backtrace #362

thewh1teagle opened this issue Apr 21, 2024 · 2 comments

Comments

@thewh1teagle
Copy link

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

@bjorn3
Copy link

bjorn3 commented Jun 19, 2024

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.

@MrFoxPro
Copy link

MrFoxPro commented Jul 8, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants