[前][次][番号順一覧][スレッド一覧]

ruby-changes:67439

From: David <ko1@a...>
Date: Tue, 31 Aug 2021 19:07:29 +0900 (JST)
Subject: [ruby-changes:67439] 1663dd5f73 (master): [rubygems/rubygems] Simplify rescue of bundler errors

https://git.ruby-lang.org/ruby.git/commit/?id=1663dd5f73

From 1663dd5f73c514343937cc018f5371dbffdeed99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Tue, 13 Apr 2021 12:13:59 +0200
Subject: [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 a7d378e..2f8c739 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -1109,21 +1109,22 @@ An Array (#{env.inspect}) was passed in from #{caller[3]} https://github.com/ruby/ruby/blob/trunk/lib/rubygems.rb#L1109
 
     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
 
   ##
-- 
cgit v1.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]