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

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Aaron Kromer-2
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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Kasper Timm Hansen
Hey, nice catch!


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

Do submit a PR 👍

Den 2. apr. 2018 kl. 15.34 skrev Aaron Kromer <[hidden email]>:

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.

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Aaron Kromer-2
Looks like this is already in Rail 5.2. It was fixed on master back in Oct. 2017 in https://github.com/rails/rails/pull/30750. :-D

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Kasper Timm Hansen
Little late for an April fools there, Aaron 😄

I guess we both should learn to check the master branch 😇

Den 2. apr. 2018 kl. 19.28 skrev Aaron Kromer <[hidden email]>:

Looks like this is already in Rail 5.2. It was fixed on master back in Oct. 2017 in https://github.com/rails/rails/pull/30750. :-D

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

--
Kasper

--
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 [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.