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

Wrapping errors looses diagnostic information #286

Open
LMH01 opened this issue Aug 21, 2023 · 0 comments
Open

Wrapping errors looses diagnostic information #286

LMH01 opened this issue Aug 21, 2023 · 0 comments

Comments

@LMH01
Copy link

LMH01 commented Aug 21, 2023

I observed that diagnostic information is not rendered when an error is wrapped using wrap_err() even though it should be (if I understand #170 and #172 correctly).

Example:

fn main() -> Result<()> {
    let source_error = SourceError {};

    let caused_error: CausedErrorA = CausedErrorA {
        reason: source_error
    };

    let main_error = MainError {
        src: NamedSource::new(
            "test.txt",
            "This is a test\nMore Test Code\nThis is the third line",
        ),
        bad_bit: (0, 4).into(),
        reason: caused_error,
    };
    //Err(main_error).wrap_err("Outer a").wrap_err("Outer b").wrap_err("Outer c")?;
    Err(main_error)?;
    Ok(())
}

#[derive(Debug, Diagnostic, Error)]
#[error("Main error")]
#[diagnostic(code("1"))]
struct MainError {
    #[source_code]
    src: NamedSource,
    #[label("here")]
    bad_bit: SourceSpan,
    #[source]
    #[diagnostic_source]
    reason: CausedErrorA,
}

#[derive(Debug, Diagnostic, Error)]
#[error("Caused error a")]
#[diagnostic(code("2"), help("This should not happen"))]
struct CausedErrorA {
    #[source]
    #[diagnostic_source]
    reason: SourceError
}

#[derive(Debug, Diagnostic, Error)]
#[error("source error")]
#[diagnostic(code("3"), help("Hello, World!"))]
struct SourceError {

}

Running this yields the following output:
image

If we instead wrap the resulting error in some error messages we receive the following output:
image

From my understanding this is wrong because the diagnostics of SourceError and CausedErrorA are not displayed like in the first picture.

I'm using version v5.10.0, downgrading to v5.9.0 did not fix the issue.
It seems like this issue should have been fixed/implemented in #170.

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

1 participant