feat: add CapturePanic method - #1395
Open
giortzisg wants to merge 1 commit into
Open
Conversation
giortzisg
force-pushed
the
scopes/capture-panic
branch
from
August 31, 2026 10:50
7a884ad to
08c24bd
Compare
Comment on lines
+793
to
794
| event.Exception[len(event.Exception)-1].Stacktrace = stacktrace | ||
| case string: |
There was a problem hiding this comment.
Bug: In capturePanic, accessing event.Exception after a call to eventFromException without checking if the slice is empty can cause a panic within the panic handler.
Severity: HIGH
Suggested Fix
Before accessing event.Exception[len(event.Exception)-1] in the error case within capturePanic, add a guard to check that len(event.Exception) > 0. If the slice is empty, the logic should proceed to the existing handling for empty exceptions, which creates a Thread with the stacktrace.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location: client.go#L793-L794
Potential issue: In the `capturePanic` function, when handling a panic value of type
`error`, the code calls `client.eventFromException` and then immediately accesses
`event.Exception[len(event.Exception)-1]` to assign a stacktrace. However,
`eventFromException` can return an event with an empty `Exception` slice, for example if
`client.options.MaxErrorDepth` is configured to be 0. If this occurs, the unguarded
slice access will cause an index-out-of-bounds panic. Because this happens inside the
panic handler itself, it will cause an unrecoverable application crash instead of
capturing the original panic.
Did we get this right? 👍 / 👎 to inform future reviews.
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.
Description
This adds a convenience method to capture panics. Panics even as messages should always have an active stacktrace, so this PR also changes the old recover behavior to include stacktraces on captured string literals.
Issues
Changelog Entry Instructions
To add a custom changelog entry, uncomment the section above. Supports:
For more details: custom changelog entries
Reminders
feat:,fix:,ref:,meta:)