Skip to content

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

@mrhead

Description

@mrhead

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 #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 #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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions