Workaround Bundler's friendly errors swallowing error reports #634
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 a script with
bundle exec <file>
orbundle exec ruby <file>
, Bundler will wrap any uncaught exceptions in aSystemExit
— see rubygems/rubygems#3368 andfriendly_errors.rb
This means that the uncaught exceptions are ignored by default, as we don't report
SystemExit
exceptions, which can lead to real errors not being reportedThis PR attempts to workaround this behaviour by trying to "unwrap" the original exception from the
SystemExit
. This is made more complicated by it being possible to have two levels ofSystemExit
exceptions, if an executable script is run directly withbundle exec <file>
. In this case we unwrap the "friendly errors"SystemExit
and then unwrap the original exceptionIt's also important that we don't unwrap other
SystemExit
exceptions, because then we will report any time an exit is used in arescue
block, e.g.Design
I'm not a huge fan of inspecting the backtrace for specific files, but they have stayed consistent for years so it should be fairly safe. I wasn't able to find another way to do this that didn't also result in reporting legitimate exits
Changeset
unwrap_bundler_exception
which is used in theat_exit
hookTesting
The maze runner tests run the same files with the same results using both
bundle exec
andbundle exec ruby
, which proves we can unwrap 1 or 2 levels of exceptions as neededThe new
exit_after_exception
test ensures we don't report exits outside of Bundler