ActiveJob custom `retry_on` logic fails with `NoMethodError: undefined method 'cause' for SomeError:Class`

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}”

def perform
# do something which causes an error
raise SomeError


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|


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.

Hey, nice catch!

Think we should raise the error instead of the exception here:

That would match rescue_from which retry_on is a veneer on top of.

Do submit a PR :+1:

Looks like this is already in Rail 5.2. It was fixed on master back in Oct. 2017 in :smiley:

Little late for an April fools there, Aaron :smile:

I guess we both should learn to check the master branch :innocent: