Skip to content

Commit

Permalink
Merge pull request #373 from sharshenov/rescue-from-script-errors
Browse files Browse the repository at this point in the history
Rescue from ScriptError
  • Loading branch information
gabrieljoelc authored Nov 6, 2018
2 parents c1b47f9 + 41c2c92 commit fa4793d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/sneakers/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def process_work(delivery_info, metadata, msg, handler)
res = work(deserialized_msg)
end
end
rescue => ex
rescue StandardError, ScriptError => ex
res = :error
error = ex
worker_error(ex, log_msg: log_msg(msg), class: self.class.name,
Expand Down
10 changes: 10 additions & 0 deletions spec/sneakers/worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ def work(msg)
w.do_work(header, nil, "msg", handler)
end

it "should catch script exceptions from a bad work" do
w = AcksWorker.new(@queue, TestPool.new)
mock(w).work("msg").once{ raise ScriptError }
handler = Object.new
header = Object.new
mock(handler).error(header, nil, "msg", anything)
mock(w.logger).error(/\[Exception error="ScriptError" error_class=ScriptError worker_class=AcksWorker backtrace=.*/)
w.do_work(header, nil, "msg", handler)
end

it "should log exceptions from workers" do
handler = Object.new
header = Object.new
Expand Down

0 comments on commit fa4793d

Please sign in to comment.