Convert frozen middleware error into a warning in the Rails integration #611
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal
When running RSpec in a Rails app which has an error in the boot process, Bugsnag will appear to be throwing errors when injecting middleware because the Rails app's middleware stack is frozen (see #534). This isn't actually caused by Bugsnag; the error in the Rails boot process freezes the middleware and when RSpec attempts to run the subsequent files it's never unfrozen. This makes frozen middleware errors inevitable, unless nothing adds middleware, but if we run first then we'll trigger the error. 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
This comment explains what happens in depth: thoughtbot/factory_bot_rails#303 (comment)
Tests
I've manually tested this catches the frozen error that us trying to inject middleware causes when running RSpec in a broken Rails app. The setup for this is super convoluted and isn't really worth automating — it's possible in a maze runner scenario but you'd need a rails app specifically setup to trigger this and some RSpec tests to run and parse the RSpec output for stack frames with 'bugsnag' in them
Linked issues
Fixes #534
Review
For the submitter, initial self-review:
For the pull request reviewer(s), this changeset has been reviewed for: