dtolnay/anyhow

`anyhow!(e)` doesn't preserve `source` for `&Error`

Opened this issue · 1 comments

#![feature(lazy_cell)]

use std::sync::LazyLock;


static ERR: LazyLock<anyhow::Error> =
    LazyLock::new(|| anyhow::anyhow!("original err").context("ctx"));

fn main() {
    std::env::set_var("RUST_BACKTRACE", "0");
    let err = anyhow::anyhow!(&*ERR);
    // ctx
    println!("{:?}", err);
    // source: None
    println!("source: {:?}", err.source());

    // However, it seems that we have "source" here?

    // Error {
    //     context: "ctx",
    //     source: "original err",
    // }
    println!("{:#?}", err);
}

The same goes it seems for Box<dyn Error> which is sad.

Sorry, it seems my example is wrong and it's preserved.