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

Improve handler panic reporting #145

Merged
merged 1 commit into from
Mar 14, 2022
Merged

Improve handler panic reporting #145

merged 1 commit into from
Mar 14, 2022

Conversation

bluekeyes
Copy link
Member

Stack traces for handler panics were lost, making it hard to determine where the panic actually happened. Now, stack traces are captured by a special error type so that handlers can print them. By default, nothing actually changes, but I plan to extend the default configuration of go-baseapp so that these errors are formatted with stack traces in logs.

I copied the error code from my implementation in bluekeyes/hatpear so that they'll share the same interface. The pkg/errors package has a similar interface, but uses package-specific types. Using standard library types seemed preferrable, even though we have a dependency on pkg/errors already.

Closes #47. Requires apps to use palantir/go-baseapp#87 or implement their own error handlers to get the benefits.

Stack traces for handler panics were lost, making it hard to determine
where the panic actually happened. Now, stack traces are captured by a
special error type so that handlers can print them. By default, nothing
actually changes, but I plan to extend the default configuration of
go-baseapp so that these errors are formatted with stack traces in logs.

I copied the error code from my implementation in `bluekeyes/hatpear` so
that they'll share the same interface. The `pkg/errors` package has a
similar interface, but uses package-specific types. Using standard
library types seemed preferrable, even though we have a dependency on
`pkg/errors` already.
@bluekeyes bluekeyes requested a review from a team March 11, 2022 21:41
var (
// HandlerRecoverStackDepth is the max depth of stack trace to recover on a
// handler panic.
HandlerRecoverStackDepth = 32
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this is 32? Or is that just a reasonable best guess?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a guess. A limit is required because of how the standard library reads stack frames and 32 seems like a good balance between not being too big but having enough context to understand where the panic came from. For this, I copied the value from hatpear and when I wrote that, I probably copied what pkg/errors used, but I don't remember.

@bluekeyes bluekeyes merged commit 7ee8345 into develop Mar 14, 2022
@bluekeyes bluekeyes deleted the bkeyes/panic-error branch March 14, 2022 16:47
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.

Capture stack traces for recovered handler panics
2 participants