Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActiveJob::DeserializationError is not reported in ActionMailer #1164

Open
tmimura39 opened this issue Sep 4, 2024 · 1 comment
Open

ActiveJob::DeserializationError is not reported in ActionMailer #1164

tmimura39 opened this issue Sep 4, 2024 · 1 comment
Labels

Comments

@tmimura39
Copy link

I use ActionMailer.

Since we are using ActionMailer, Rollbar::ActiveJob is automatically applied.

ActionMailer::Base.send(:include, Rollbar::ActiveJob)

This makes it very convenient that any exceptions that occur during the mail sending process are automatically reported to the Rollbar.

Steps to reproduce

  1. Prepare a Mailer class like this
class ExampleMailer < ApplicationMailer
  def hello(user)
   # something...
  end
end
  1. Specify a non-existent User as an argument and execute the mail sending process.
ExampleMailer.hello(User.new(id: -1)).deliver_later
  1. ActiveJob::DeserializationError occurs due to non-existent User and mail sending fails.

Expected behavior

Reported in Rollbar

Actual behavior

Not reported in Rollbar

Possible Causes

However, I noticed that Rollbar is not notified about ActiveJob::DeserializationError.
#1146 We believe this fix is the cause.

This fix is intended to prevent double reporting of exceptions generated inside ActionMailer.

The following is controlled for ActionMailer.

# When included in ActionMailer, the handler is called twice.
# This detects the execution that has the expected state.
if defined?(ActionMailer::Base) && self.class.ancestors.include?(ActionMailer::Base)
  Rollbar.error(exception, job_data)
# This detects other supported integrations.
elsif defined?(arguments)
  Rollbar.error(exception, job_data)
end

In the case of ActiveJob::DeserializationError, self is the Mailer class itself, so self.class.ancestors.include?(ActionMailer::Base) #=> false is determined.
No arguments are defined for the ActionMailer class itself.

The result does not seem to be reported in Rollbar.

This PullRequest is also helpful.
rails/rails#25018

Workaround

If you rescue_from ActiveJob::DeserializationError in the Mailer class, you can notify Rollbar as expected.

class ApplicationMailer < ActionMailer::Base
  rescue_from ActiveJob::DeserializationError do |exception|
     Rollbar.error(exception)
  end
end
Copy link

linear bot commented Sep 4, 2024

@zdavis-rollbar zdavis-rollbar added the Ruby label Sep 4, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants