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

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

Open
xxchan opened this issue Jan 3, 2024 · 1 comment
Open

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

xxchan opened this issue Jan 3, 2024 · 1 comment

Comments

@xxchan
Copy link

xxchan commented Jan 3, 2024

#![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);
}
@blind-oracle
Copy link

blind-oracle commented May 29, 2024

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

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

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

2 participants