anyhow icon indicating copy to clipboard operation
anyhow copied to clipboard

anyhow's dyn error `backtrace` disagrees with `anyhow::Error::backtrace`

Open guswynn opened this issue 2 years ago • 0 comments

#![feature(backtrace)]
use anyhow;
use thiserror::Error;

#[derive(Error, Debug)]
enum Gus {
    #[error("hmm")]
    Other(
        #[from]
        #[backtrace]
        anyhow::Error,
    ),
}
fn main() {
    use std::error::Error;
    use std::ops::Deref;
    println!("{:?}", Gus::from(anyhow::anyhow!("main")));
    println!("{:?}", Gus::from(anyhow::anyhow!("main")).backtrace());
    println!("{:?}", anyhow::anyhow!("main").deref().backtrace());
}

results in

>printing the error with a backtrace
None
None

Looking briefly at the code, this appears to be at least semi-on-purpose, where the vtable for adhoc errors points to no_backtrace, but it links the backtrace back in somehow? can the ErrorImpl coercion do the same things as https://github.com/dtolnay/anyhow/blob/6833150a7965ad9f489a1da619298ba84b8d3148/src/error.rs#L880?

(also, is there a reason the backtrace is only printed for the Debug impl, not the Display impl, should the docs be updated to reflect that?)

guswynn avatar Mar 25 '22 14:03 guswynn