Skip to content

Commit b51d335

Browse files
committed
[fix] Ensure all Throwables occurring during exception metadata capture are handled
While this shouldn't happen, currently if it does, the root exception is lost, which can be catastrophic for debugging.
1 parent ec9610e commit b51d335

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/main/java/org/jruby/rack/DefaultRackApplicationFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ private void captureMessage(final RaiseException re) {
483483
rubyException.callMethod(context, "capture");
484484
rubyException.callMethod(context, "store");
485485
}
486-
catch (Exception e) {
486+
catch (Throwable e) {
487487
rackContext.log(INFO, "failed to capture exception message", e);
488488
// won't be able to capture anything
489489
}

src/spec/ruby/rack/application_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,35 @@ def reset_config
487487
expect(e.message).to eql 'something went wrong'
488488
end
489489
end
490+
491+
it "swallows and logs errors during exception detail capturing" do
492+
expect(@rack_config).to receive(:getRackup).and_return("raise 'something went wrong'")
493+
expect_any_instance_of(Exception).to receive(:capture).and_raise java.lang.NoClassDefFoundError.new("missing class during exception capture")
494+
495+
app_factory = mocked_runtime_application_factory
496+
app_factory.init @rack_context
497+
app_object = app_factory.newApplication
498+
499+
raise_info_logged = 0
500+
allow(@rack_context).to receive(:log) do |level, msg, e|
501+
if level.to_s == 'INFO'
502+
expect(msg).to eql 'failed to capture exception message'
503+
expect(e).to be_a java.lang.NoClassDefFoundError
504+
raise_info_logged += 1
505+
else
506+
true
507+
end
508+
end
509+
510+
begin
511+
app_object.init
512+
fail "expected to raise"
513+
rescue => e
514+
expect(e.message).to eql 'something went wrong' # original error
515+
end
516+
517+
expect(raise_info_logged).to eql 1 # logs info message for exception capture
518+
end
490519
end
491520

492521
describe "getApplication" do

0 commit comments

Comments
 (0)