-
Notifications
You must be signed in to change notification settings - Fork 97
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
Remove irrelevant frames from panic traces #774
Conversation
836d3cc
to
d047c48
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Yeah, this should make these things a lot easier to read.
@@ -131,7 +131,7 @@ func (e *JobExecutor) execute(ctx context.Context) (res *jobExecutorResult) { | |||
) | |||
|
|||
res = &jobExecutorResult{ | |||
PanicTrace: string(debug.Stack()), | |||
PanicTrace: captureStackTraceSkipFrames(4), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the formatting comes from what debug.Stack()
would be doing? A little unfortunate that we have to format it manually here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is actually quite a bit easier to grok than the stdlib 😬 :
This is more similar to what pkg/errors does:
https://github.com/pkg/errors/blob/5dd12d0cfe7f152f80558d591504ce685299311e/stack.go#L68-L71
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.
d047c48
to
86c8c5b
Compare
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.