Skip to content

Commit

Permalink
Changed the way the error message is composed when a job fails. Whith…
Browse files Browse the repository at this point in the history
… 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
jorgemanrubia committed Oct 15, 2010
1 parent aba9905 commit 2b23b80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions lib/delayed/backend/shared_spec.rb
Expand Up @@ -345,6 +345,7 @@ def create_job(opts = {})
Delayed::Worker.max_run_time = old_max_run_time
end
end

end

context "worker prioritization" do
Expand Down Expand Up @@ -433,6 +434,13 @@ def create_job(opts = {})

(Delayed::Job.db_time_now + 99.minutes - @job.run_at).abs.should < 1
end

it "should not fail when the triggered error doesn't have a message" do
error_with_nil_message = StandardError.new
error_with_nil_message.stub!(:message).and_return nil
@job.stub!(:invoke_job).and_raise error_with_nil_message
lambda{@worker.run(@job)}.should_not raise_error
end
end

context "reschedule" do
Expand Down
2 changes: 1 addition & 1 deletion lib/delayed/worker.rb
Expand Up @@ -152,7 +152,7 @@ def say(text, level = Logger::INFO)
protected

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 "#{job.name} failed with #{error.class.name}: #{error.message} - #{job.attempts} failed attempts", Logger::ERROR
reschedule(job)
end
Expand Down

0 comments on commit 2b23b80

Please sign in to comment.