Skip to content

feat: add CapturePanic method - #1395

Open
giortzisg wants to merge 1 commit into
scopes/integration-primitivesfrom
scopes/capture-panic
Open

feat: add CapturePanic method#1395
giortzisg wants to merge 1 commit into
scopes/integration-primitivesfrom
scopes/capture-panic

Conversation

@giortzisg

Copy link
Copy Markdown
Contributor

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:

  • Single entry: just write text
  • Multiple entries: use bullet points
  • Nested bullets: indent 4+ spaces

For more details: custom changelog entries

Reminders

@giortzisg
giortzisg force-pushed the scopes/capture-panic branch from 7a884ad to 08c24bd Compare August 31, 2026 10:50
Comment thread client.go
Comment on lines +793 to 794
event.Exception[len(event.Exception)-1].Stacktrace = stacktrace
case string:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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.

1 participant