Browse files

Changed the way the error message is composed when a job fails. Whith…

… the previous implementation, if the raised error has a nil message, it will fail with a `<NoMethodError: undefined method '+' for nil:NilClass>`. Now it is using normal Ruby interpolation that will default to an empty String with nil messages.

Having an exception with a nil message is not a normal Ruby behaviour (Exceptions usually default to its class name when no message is provided), but it is possible. I am experiencing this problem because I am using the Ruby EDAM implementation of a commercial API, that doesn't set a message for its errors. The problem with delayed_job is quite serious, since it makes the jobs worker to crash completely (it kills the process).
  • Loading branch information...
1 parent aba9905 commit 2b23b809b4a7ce2422ef2c758b216f8341453e18 @jorgemanrubia jorgemanrubia committed Oct 15, 2010
Showing with 9 additions and 1 deletion.
  1. +8 −0 lib/delayed/backend/shared_spec.rb
  2. +1 −1 lib/delayed/worker.rb
@@ -345,6 +345,7 @@ def create_job(opts = {})
Delayed::Worker.max_run_time = old_max_run_time
context "worker prioritization" do
@@ -433,6 +434,13 @@ def create_job(opts = {})
(Delayed::Job.db_time_now + 99.minutes - @job.run_at).abs.should < 1
+ it "should not fail when the triggered error doesn't have a message" do
+ error_with_nil_message =
+ error_with_nil_message.stub!(:message).and_return nil
+ @job.stub!(:invoke_job).and_raise error_with_nil_message
+ lambda{}.should_not raise_error
+ end
context "reschedule" do
@@ -152,7 +152,7 @@ def say(text, level = Logger::INFO)
def handle_failed_job(job, error)
- job.last_error = error.message + "\n" + error.backtrace.join("\n")
+ job.last_error = "{#{error.message}\n#{error.backtrace.join('\n')}"
say "#{} failed with #{}: #{error.message} - #{job.attempts} failed attempts", Logger::ERROR

0 comments on commit 2b23b80

Please sign in to comment.