Skip to content

Commit

Permalink
Simplify rescue of bundler errors
Browse files Browse the repository at this point in the history
As far as I understand, this block should only be run when
`bundler/setup` fails. The only other case where these errors could be
run is when bundler itself is required.

If bundler itself fails to be required or activated (like in old rubies
where it was not a default gem, for example), the raw error is much more
helpful than this message.

So we can move the rescue after bundler is succesfully required, and
that simplifies the list of exceptions that we need to track to just
`Bundler::Error`.
  • Loading branch information
deivid-rodriguez committed Aug 4, 2021
1 parent 5edf74b commit 3663c11
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/rubygems.rb
Expand Up @@ -1109,21 +1109,22 @@ def self.use_gemdeps(path = nil)

ENV["BUNDLE_GEMFILE"] ||= File.expand_path(path)
require 'rubygems/user_interaction'
Gem::DefaultUserInteraction.use_ui(ui) do
require "bundler"
begin
Bundler.ui.silence do
@gemdeps = Bundler.setup
require "bundler"
begin
Gem::DefaultUserInteraction.use_ui(ui) do
begin
Bundler.ui.silence do
@gemdeps = Bundler.setup
end
ensure
Gem::DefaultUserInteraction.ui.close
end
ensure
Gem::DefaultUserInteraction.ui.close
end
rescue Bundler::BundlerError => e
warn e.message
warn "You may need to `gem install -g` to install missing gems"
warn ""
end

rescue Gem::LoadError, Gem::UnsatisfiableDependencyError, (defined?(Bundler::GemNotFound) ? Bundler::GemNotFound : Gem::LoadError) => e
warn e.message
warn "You may need to `gem install -g` to install missing gems"
warn ""
end

##
Expand Down

0 comments on commit 3663c11

Please sign in to comment.