From 1663dd5f73c514343937cc018f5371dbffdeed99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rodr=C3=ADguez?= Date: Tue, 13 Apr 2021 12:13:59 +0200 Subject: [PATCH] [rubygems/rubygems] Simplify rescue of bundler errors 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`. https://github.com/rubygems/rubygems/commit/3663c11e93 --- lib/rubygems.rb | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/lib/rubygems.rb b/lib/rubygems.rb index a7d378e2d3..2f8c73972f 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -1109,21 +1109,22 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} 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 ##