diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d281d529..d929140dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Bug Fixes + +- Handle empty frames case gracefully with local vars ([#2807](https://github.com/getsentry/sentry-ruby/pull/2807)) + ## 6.2.0 ### Features diff --git a/sentry-ruby/lib/sentry/interfaces/single_exception.rb b/sentry-ruby/lib/sentry/interfaces/single_exception.rb index 1753ed0ae..883e5946e 100644 --- a/sentry-ruby/lib/sentry/interfaces/single_exception.rb +++ b/sentry-ruby/lib/sentry/interfaces/single_exception.rb @@ -60,7 +60,7 @@ def self.build_with_stacktrace(exception:, stacktrace_builder:, mechanism:) end end - stacktrace.frames.last.vars = locals + stacktrace.frames.last&.vars = locals end new(exception: exception, stacktrace: stacktrace, mechanism: mechanism) diff --git a/sentry-ruby/spec/sentry_spec.rb b/sentry-ruby/spec/sentry_spec.rb index 6bae570a7..581058db9 100644 --- a/sentry-ruby/spec/sentry_spec.rb +++ b/sentry-ruby/spec/sentry_spec.rb @@ -310,6 +310,16 @@ last_frame = event.dig(:exception, :values, 0, :stacktrace, :frames).last expect(last_frame[:vars]).to include({ a: "1", b: "0" }) end + + it 'does not throw SDK internal exception with empty frames' do + expect do + begin + raise StandardError, 'Stuff', [] + rescue => e + Sentry.capture_exception(e) + end + end.not_to raise_error + end end end