Remove irrelevant frames from panic traces - #774
Merged
Conversation
bgentry
force-pushed
the
bg-better-panic-stack-traces
branch
from
February 19, 2025 02:58
836d3cc to
d047c48
Compare
brandur
approved these changes
Feb 19, 2025
brandur
left a comment
Contributor
There was a problem hiding this comment.
Nice. Yeah, this should make these things a lot easier to read.
|
|
||
| res = &jobExecutorResult{ | ||
| PanicTrace: string(debug.Stack()), | ||
| PanicTrace: captureStackTraceSkipFrames(4), |
Contributor
There was a problem hiding this comment.
Oof, it's good there's a test for this because it'd be pretty shaky otherwise. The raw number "4" probably merits a comment.
Contributor
Author
There was a problem hiding this comment.
Added a comment to explain and further improved test coverage, thanks
| var stackTrace string | ||
| for { | ||
| frame, more := frames.Next() | ||
| stackTrace += fmt.Sprintf("%s\n\t%s:%d\n", frame.Function, frame.File, frame.Line) |
Contributor
There was a problem hiding this comment.
I assume the formatting comes from what debug.Stack() would be doing? A little unfortunate that we have to format it manually here.
Contributor
Author
There was a problem hiding this comment.
This is actually quite a bit easier to grok than the stdlib 😬 :
This is more similar to what pkg/errors does:
Adjusted panic stack traces to filter out irrelevant frames like the ones generated by the runtime package that constructed the trace, or River's internal rescuing code. This makes the first panic frame reflect the actual panic origin for easier debugging.
bgentry
force-pushed
the
bg-better-panic-stack-traces
branch
from
February 19, 2025 16:42
d047c48 to
86c8c5b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While testing the
rivertest.Worker, I realized the panic traces we're sending to the panic handler have initial frames that reflect the code that actually generates the trace, rather than starting with the user's code that actually panicked:To improve this, I adjusted the panic stack traces to filter out irrelevant frames like the ones generated by the runtime package that constructed the trace, or River's internal rescuing code. This makes the first panic frame reflect the actual panic origin for easier debugging. The unit test now ensures that the first frame is actually from the test file instead of stdlib runtime code.