eyre-rs / eyre

A trait object based error handling type for easy idiomatic error handling and reporting in Rust applications
Apache License 2.0
1.41k stars 68 forks source link

Add #[track_caller] to `format_err` #70

Closed Hoverbear closed 2 years ago

Hoverbear commented 2 years ago

eyre isn't reporting error locations correctly right now. (😢 )

Example source:

fn main() -> color_eyre::Result<()> {
    color_eyre::install()?;

    Err(eyre::eyre!("Whoops"))
}

Released version:

ana@autonoma:~/git/eyre-demo$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 1.74s
     Running `target/debug/eyre-demo`
Error: 
   0: Whoops

Location:
   /home/ana/.cargo/registry/src/github.com-1ecc6299db9ec823/eyre-0.6.6/src/lib.rs:1164

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.

After this patch it is resolved:

ana@autonoma:~/git/eyre-demo$ cargo run
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/eyre-demo`
Error: 
   0: Whoops

Location:
   src/main.rs:4

Backtrace omitted.
Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.