Skip to content

Commit

Permalink
🥅 Add blanket rescue to DeprecationWarningSubscriber
Browse files Browse the repository at this point in the history
(Puts on tin foil hat) Prevent potential exceptions from SlackService from impacting user experience
  • Loading branch information
jcroteau committed Aug 10, 2023
1 parent f912429 commit c633966
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions config/initializers/deprecation_warning_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def deprecation(event)
emit_warning_to_application_logs(event)
emit_warning_to_sentry(event)
emit_warning_to_slack_alerts_channel(event)
rescue StandardError => error
Raven.capture_exception(error)
end

private
Expand Down
26 changes: 25 additions & 1 deletion spec/initializers/deprecation_warning_subscriber_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
allow(rails_logger).to receive(:warn)

allow(Raven).to receive(:capture_message)
allow(Raven).to receive(:capture_exception)

allow(SlackService).to receive(:new).with(url: anything).and_return(slack_service)
allow(slack_service).to receive(:send_notification)
Expand All @@ -28,13 +29,19 @@
let(:location_1) { instance_double("Thread::Backtrace::Location", to_s: "location 1") }
let(:location_2) { instance_double("Thread::Backtrace::Location", to_s: "location 2") }

before { ActiveSupport::Notifications.instrument("deprecation.rails", payload) }
def instrument_deprecation_warning
ActiveSupport::Notifications.instrument("deprecation.rails", payload)
end

it "emits a warning to the application logs" do
instrument_deprecation_warning

expect(rails_logger).to have_received(:warn).with(payload[:message])
end

it "emits a warning to Sentry" do
instrument_deprecation_warning

expect(Raven).to have_received(:capture_message).with(
payload[:message],
level: "warning",
Expand All @@ -50,11 +57,28 @@

it "emits a warning to Slack channel" do
slack_alert_title = "Deprecation Warning - #{app_name} (#{deploy_env})"

instrument_deprecation_warning

expect(slack_service).to have_received(:send_notification).with(
payload[:message],
slack_alert_title,
"#appeals-deprecation-alerts"
)
end

context "when an exeption ocurrs" do
before { allow(slack_service).to receive(:send_notification).and_raise(StandardError) }

it "logs error to Sentry" do
instrument_deprecation_warning

expect(Raven).to have_received(:capture_exception).with(StandardError)
end

it "does not raise error" do
expect { instrument_deprecation_warning }.not_to raise_error
end
end
end
end

0 comments on commit c633966

Please sign in to comment.