rollbar-gem icon indicating copy to clipboard operation
rollbar-gem copied to clipboard

Rollbar reports Action Mailer errors that are handled with `discard_on` and `rescue_from` in the delivery job

Open mrhead opened this issue 8 months ago • 1 comments

Since version 3.5.1, Rollbar reports errors raised from Action Mailer even if they are handled with discard_on or rescue_from in the delivery job.

In fact, this behavior changed in 3.5.0, but this version fails because of https://github.com/rollbar/rollbar-gem/issues/1145.

Steps to reproduce

require "bundler/inline"

gemfile(true) do
  source "https://rubygems.org"

  gem "rails"
  gem "rollbar", ENV["ROLLBAR_VERSION"]
  gem "minitest"
end

require "rails/all"
require "rollbar"
require "minitest/autorun"

ActiveJob::Base.queue_adapter = :async
ActiveJob::Base.queue_adapter.immediate = true

Rollbar.configure do |config|
  config.access_token = "dummy token"
end

class InactiveRecipientError < StandardError; end

class TestDeliveryJob < ActionMailer::MailDeliveryJob
  discard_on InactiveRecipientError
end

class TestMailer < ActionMailer::Base
  self.delivery_job = TestDeliveryJob

  def mail(to:)
    raise InactiveRecipientError # simulate error
  end
end

class RollbarReportingTest < Minitest::Test
  def test_rollbar_reports_abort_email_exception
    TestMailer.mail(to: "[email protected]").deliver_later

    assert_nil Rollbar.last_report, "Rollbar should not report InactiveRecipientError exception"
  end
end

Save the script to rollbar_actionmailer.rb and run it with:

ROLLBAR_VERSION=3.5.1 ruby rollbar_actionmailer.rb

You can also test it with Rollbar in 3.5.0; however, 3.5.0 fails because of https://github.com/rollbar/rollbar-gem/issues/1145.

ROLLBAR_VERSION=3.5.0 ruby rollbar_actionmailer.rb

Expected behavior

The InactiveRecipientError error should not be reported, and the test should pass as it does with Rollbar 3.4.2.

ROLLBAR_VERSION=3.4.2 ruby rollbar_actionmailer.rb

Actual behavior

The error is reported even if it is handled by discard_on or rescue_from in the delivery job and the test fails.

mrhead avatar Feb 18 '25 14:02 mrhead