Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/interfaces/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def self.build(exception:, stacktrace_builder:, mechanism:, data_collection:)
data_collection: data_collection
)
else
SingleExceptionInterface.new(exception: exception, mechanism: mechanism)
SingleExceptionInterface.new(exception: e, mechanism: mechanism)
end
end

Expand Down
24 changes: 24 additions & 0 deletions sentry-ruby/spec/sentry/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,30 @@ module ExcTag; end
end
end

context 'when a cause shares its backtrace with its own cause' do
let(:exception) { build_exception_with_shared_backtrace_cause }

it 'captures the type and message of each cause' do
expect(hash[:exception][:values].map { |value| value[:type] }).to eq(["ArgumentError", "TypeError", "RuntimeError"])
expect(hash[:exception][:values][1][:value]).to match("exception b")
end

it 'captures the shared stacktrace once' do
expect(hash[:exception][:values][0][:stacktrace]).not_to be_nil
expect(hash[:exception][:values][1][:stacktrace]).to be_nil
end
end

context 'when a cause has no backtrace' do
let(:exception) { build_exception_with_stackless_cause }

it 'captures the type and message of the cause' do
expect(hash[:exception][:values][0][:type]).to eq("Errno::ENOENT")
expect(hash[:exception][:values][0][:module]).to eq("Errno")
expect(hash[:exception][:values][0][:value]).to match("exception a")
end
end

context 'when the exception has a recursive cause' do
let(:exception) { build_exception_with_recursive_cause }

Expand Down
26 changes: 26 additions & 0 deletions sentry-ruby/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,32 @@ def build_exception_with_two_causes
e
end

def build_exception_with_shared_backtrace_cause
inner = begin
raise ArgumentError, "exception a"
rescue ArgumentError => e
e
end

begin
begin
middle = TypeError.new("exception b")
middle.set_backtrace(inner.backtrace)
raise middle, cause: inner
rescue TypeError
raise "exception c"
end
rescue RuntimeError => e
e
end
end

def build_exception_with_stackless_cause
raise "exception b", cause: Errno::ENOENT.new("exception a")
rescue RuntimeError => e
e
end

def build_exception_with_recursive_cause
backtrace = []

Expand Down