From f4076aa1f067c49a4d68478d94a48d002f31e006 Mon Sep 17 00:00:00 2001 From: shashank mehra Date: Fri, 16 May 2025 15:15:38 +0530 Subject: [PATCH] Handle and reraise Bunny exceptions when raised from work --- lib/sneakers/worker.rb | 2 +- spec/sneakers/worker_spec.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/sneakers/worker.rb b/lib/sneakers/worker.rb index 7ea61d4d..90fc8d28 100644 --- a/lib/sneakers/worker.rb +++ b/lib/sneakers/worker.rb @@ -76,7 +76,7 @@ def process_work(delivery_info, metadata, msg, handler) end res = block_to_call.call(deserialized_msg, delivery_info, metadata, handler) end - rescue SignalException, SystemExit + rescue SignalException, SystemExit, Bunny::Exception # ServerEngine handles these exceptions, so they are not expected to be raised within the worker. # Nevertheless, they are listed here to ensure that they are not caught by the rescue block below. raise diff --git a/spec/sneakers/worker_spec.rb b/spec/sneakers/worker_spec.rb index ea19fc53..7587898d 100644 --- a/spec/sneakers/worker_spec.rb +++ b/spec/sneakers/worker_spec.rb @@ -446,6 +446,14 @@ def work(msg) w.do_work(header, nil, "msg", handler) end + it "should not catch bunny exceptions" do + w = DummyWorker.new(@queue, TestPool.new) + mock(w).work("msg").once{ raise Bunny::Exception } + assert_raises(Bunny::Exception) do + w.do_work(nil, nil, "msg", nil) + end + end + it "should log exceptions from workers" do handler = Object.new header = Object.new