I’m not sure if this is a bug or a documentation issue. The issue is that the second argument yielded to a custom Active Job retry_on block is the exception class and not the error instance:
class SomeJob < ActiveJob::Base retry_on SomeError, attempts: 4 do |job, exception| logger.error “Job failed: #{exception.cause}” end
def perform # do something which causes an error rescue raise SomeError end end
``
According to the method description the second parameter is supposed to be:
the error instance as the second parameter
However, slightly further down the code example uses exception which mirrors the exception class provided to retry_on:
retry_on(YetAnotherCustomAppException) do |job, exception| ExceptionNotifier.caught(exception) end
``
This is in fact what is yielded to the block; the exception class not the error instance.
Is this intended design or an oversight in the initial implementation. I don’t find the exception class to be overly useful within the block, compared to the error instance.