Skip to content

Commit

Permalink
Ignore error if nested cause is ignored
Browse files Browse the repository at this point in the history
Traverse the error causes tree to see if any nested error cause is
ignored.
  • Loading branch information
tombruijn committed Sep 16, 2024
1 parent a2775db commit 46cd9ac
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/appsignal/rack/body_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ def appsignal_report_error(error)

def appsignal_accepted_error?(error)
return true unless error.cause
return false if IGNORED_ERRORS.include?(error.cause.class)

!IGNORED_ERRORS.include?(error.cause.class)
appsignal_accepted_error?(error.cause)
end
end

Expand Down
27 changes: 27 additions & 0 deletions spec/lib/appsignal/rack/body_wrapper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,19 @@
expect(transaction).to_not have_error
end

it "does not report EPIPE error when it's the nested error cause" do
error = error_with_nested_cause(StandardError, "error message", Errno::EPIPE)
fake_body = double
expect(fake_body).to receive(:each).once.and_raise(error)

wrapped = described_class.wrap(fake_body, transaction)
expect do
expect { |b| wrapped.each(&b) }.to yield_control
end.to raise_error(StandardError, "error message")

expect(transaction).to_not have_error
end

it "closes the body and tracks an instrumentation event when it gets closed" do
fake_body = double(:close => nil)
expect(fake_body).to receive(:each).once.and_yield("a").and_yield("b").and_yield("c")
Expand Down Expand Up @@ -444,4 +457,18 @@ def error_with_cause(klass, message, cause)
rescue => error
error
end

def error_with_nested_cause(klass, message, cause)
begin
begin
raise cause
rescue
raise klass, message
end
rescue
raise klass, message
end
rescue => error
error
end
end

0 comments on commit 46cd9ac

Please sign in to comment.