Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
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...
commit 2b23b809b4a7ce2422ef2c758b216f8341453e18 1 parent aba9905
@jorgemanrubia jorgemanrubia authored
Showing with 9 additions and 1 deletion.
  1. +8 −0 lib/delayed/backend/shared_spec.rb
  2. +1 −1  lib/delayed/worker.rb
View
8 lib/delayed/backend/shared_spec.rb
@@ -345,6 +345,7 @@ def create_job(opts = {})
Delayed::Worker.max_run_time = old_max_run_time
end
end
+
end
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
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
View
2  lib/delayed/worker.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.