Skip to content

Commit

Permalink
Supress frozen middleware errors in Railtie
Browse files Browse the repository at this point in the history
This should never happen in normal operation, but is possible when
running RSpec tests

See thoughtbot/factory_bot_rails#303 (comment)
and #534

Essentially this happens:
1. RSpec boots Rails
2. Rails boot process errors
3. Rails freezes middleware
4. RSpec moves on to the next test file
5. Bugsnag tries to add middleware but fails because it's frozen
6. The stacktrace blames Bugsnag for this test failure
7. goto 4

Supressing this error doesn't solve the problem as it's likely another
frozen error will happen in some other library/component, but we want
to avoid people thinking this is caused by Bugsnag. The stacktrace
does point out the actual problem, but only in the very first error,
which can get buried under the frozen errors that happen for each
test file
  • Loading branch information
imjoehaines committed Jul 23, 2020
1 parent f81c855 commit e475d92
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/bugsnag/integrations/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ class Railtie < ::Rails::Railtie
rescue
app.config.middleware.use Bugsnag::Rack
end
rescue FrozenError
# This can happen when running RSpec if there is a crash after Rails has
# started booting but before we've added our middleware. If we don't ignore
# this error then the stacktrace blames Bugsnag, which isn't accurate as
# the middleware will only be frozen if an earlier error occurs
# See this comment for more info:
# https://github.com/thoughtbot/factory_bot_rails/issues/303#issuecomment-434560625
Bugsnag.configuration.warn("Unable to add Bugsnag::Rack middleware as the middleware stack is frozen")
end

##
Expand Down

0 comments on commit e475d92

Please sign in to comment.