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

Print backtrace with Display::fmt #204

Open
musjj opened this issue Oct 6, 2024 · 0 comments
Open

Print backtrace with Display::fmt #204

musjj opened this issue Oct 6, 2024 · 0 comments

Comments

@musjj
Copy link

musjj commented Oct 6, 2024

I have an error like this:

#[derive(thiserror::Error, Debug)]
pub enum MyError {
    ...

    #[error(transparent)]
    Other(#[from] eyre::Error),
}

I want to print the error along with the backtrace and it seems the only way to do it is to use Debug::fmt:

if let Err(e) = trigger_error() {
    tracing::error!("{e:?}");
}

But this wraps the error awkwardly like this:

Other(hello i'm error

Location:                                                                                                                                                                           
    src/main.rs:1:1) 

If you use Display::fmt you can take advantage of thiserror's #[error(transparent)] feature, which gets you a cleaner output, but you lose the backtrace.

So it would be nice if there's an option for including the backtrace in the Display::fmt output.

@musjj musjj changed the title Print backtrace without using Debug::fmt Print backtrace with Display::fmt Oct 6, 2024
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