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 
<https://github.com/rails/rails/blob/v5.1.5/activejob/lib/active_job/exceptions.rb#L15>
 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 
<https://github.com/rails/rails/blob/v5.1.5/activejob/lib/active_job/exceptions.rb#L50>;
 
the *exception class* not the *error instance*.

Is this intended design or an oversight in the initial implementation 
<https://github.com/rails/rails/pull/25991>. I don't find the exception 
class to be overly useful within the block, compared to the error instance.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to