Skip to content

fix(anyhow): attach stacktrace only if anyhow error has backtrace #759

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

Merged
merged 1 commit into from
Mar 27, 2025

Conversation

lcian
Copy link
Member

@lcian lcian commented Mar 26, 2025

This is similar to #755 but for the anyhow integration

Without this change, if we're running without RUST_BACKTRACE set, then backtrace will have value "<disabled>".
We would try to parse it and get an empty vec as a result.
The consequence is that all anyhows would be grouped in a single issue due to having the same (empty) stack trace.

After the change, there will be no stack trace, so grouping will happen according to the error message.

Side effect: when running with attach_stacktrace: true, sentry-backtrace will kick in and provide a backtrace (this didn't happen before because we had a stack trace, even though it was an empty one).
It could be argued whether we want this or not.

Closes #745

Copy link
Member

@Swatinem Swatinem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice! thanks for fixing this and providing a good explanation.

Maybe it might be worth still checking exc.stacktrace if its empty, and clearing it in that case?

@lcian
Copy link
Member Author

lcian commented Mar 27, 2025

Sorry the stacktrace is not empty, it's going to have a single frame which will contain either disabled or unsupported.
We wrongly parse that and believe it's a frame.
This is due to the fact that anyhow uses some custom logic to format the backtrace https://github.com/dtolnay/anyhow/blob/master/src/backtrace.rs. Luckily they provide backtrace.status() to check it.
In general we already return None in Stacktrace::from_frames_reversed if the vec of frames is empty, so I don't think we need to check twice.

@lcian lcian merged commit 1f0be60 into master Mar 27, 2025
14 checks passed
@lcian lcian deleted the lcian/fix/anyhow-backtrace-if-captured branch March 27, 2025 10:54
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

Successfully merging this pull request may close these issues.

anyhow errors are grouped incorrectly
2 participants