anyhow
anyhow copied to clipboard
anyhow's dyn error `backtrace` disagrees with `anyhow::Error::backtrace`
#![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?)