Skip to content

Commit 478c4cf

Browse files
authored
Update backtrace parsing regexp to support Ruby 3.4 (#2252)
* Update backtrace parsing regexp to support Ruby 3.4 In Ruby 3.4, the backtrace format has changed slightly. This commit updates the regular expression used to parse the backtrace to support Ruby 3.4. See ruby/ruby#9608 for more information. * Update changelog
1 parent 27128d6 commit 478c4cf

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
- Fix undefined method 'constantize' issue in `sentry-resque` ([#2248](https://github.com/getsentry/sentry-ruby/pull/2248))
1212
- Only instantiate SessionFlusher when the SDK is enabled under the current env [#2245](https://github.com/getsentry/sentry-ruby/pull/2245)
1313
- Fixes [#2234](https://github.com/getsentry/sentry-ruby/issues/2234)
14+
- Update backtrace parsing regexp to support Ruby 3.4 ([#2252](https://github.com/getsentry/sentry-ruby/pull/2252))
1415

1516
## 5.16.1
1617

sentry-ruby/lib/sentry/backtrace.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# frozen_string_literal: true
22

3+
require "rubygems"
4+
35
module Sentry
46
# @api private
57
class Backtrace
@@ -10,7 +12,7 @@ class Line
1012
RUBY_INPUT_FORMAT = /
1113
^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>):
1214
(\d+)
13-
(?: :in \s `([^']+)')?$
15+
(?: :in\s('|`)([^']+)')?$
1416
/x.freeze
1517

1618
# org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
@@ -36,7 +38,7 @@ class Line
3638
def self.parse(unparsed_line, in_app_pattern)
3739
ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT)
3840
if ruby_match
39-
_, file, number, method = ruby_match.to_a
41+
_, file, number, _, method = ruby_match.to_a
4042
file.sub!(/\.class$/, RB_EXTENSION)
4143
module_name = nil
4244
else

sentry-ruby/spec/sentry/client_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ def sentry_context
221221
version = Gem::Version.new(RUBY_VERSION)
222222

223223
case
224+
when version >= Gem::Version.new("3.4.0-dev")
225+
expect(hash[:exception][:values][0][:value]).to eq(
226+
"undefined method '[]' for nil (NoMethodError)\n\n {}[:foo][:bar]\n ^^^^^^"
227+
)
224228
when version >= Gem::Version.new("3.3.0-dev")
225229
expect(hash[:exception][:values][0][:value]).to eq(
226230
"undefined method `[]' for nil (NoMethodError)\n\n {}[:foo][:bar]\n ^^^^^^"

0 commit comments

Comments
 (0)