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

ruby-changes:67428

From: David <ko1@a...>
Date: Tue, 31 Aug 2021 19:07:11 +0900 (JST)
Subject: [ruby-changes:67428] 0b4dbe2e6a (master): [rubygems/rubygems] Improve "gem not found in source" errors

https://git.ruby-lang.org/ruby.git/commit/?id=0b4dbe2e6a

From 0b4dbe2e6a0a0b27860fb6a509ff0429ece436c7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?David=20Rodr=C3=ADguez?= <deivid.rodriguez@r...>
Date: Sat, 31 Jul 2021 14:10:59 +0200
Subject: [rubygems/rubygems] Improve "gem not found in source" errors

When printing sources inside these error messages, it's useful to only
consider the current state of the source. For example, when requiring
`bundler/setup`, the source shouldn't be configured to be able to hit
the network, so the error message should only mention "locally installed
gems" to make that more clear.

https://github.com/rubygems/rubygems/commit/30eb14f853
---
 lib/bundler/resolver.rb                  |  4 ++--
 lib/bundler/source.rb                    |  4 ++++
 lib/bundler/source/rubygems.rb           | 17 ++++++++++++++++-
 lib/bundler/source/rubygems_aggregate.rb |  4 ++++
 spec/bundler/commands/exec_spec.rb       |  4 ++--
 spec/bundler/commands/lock_spec.rb       |  2 +-
 spec/bundler/support/indexes.rb          |  2 +-
 7 files changed, 30 insertions(+), 7 deletions(-)

diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 0e28e85..d26e2fe 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -272,7 +272,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/resolver.rb#L272
                             rescue GemfileNotFound
                               nil
                             end
-          message = String.new("Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in #{source}#{cache_message}.\n")
+          message = String.new("Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in #{source.to_err}#{cache_message}.\n")
           message << "The source contains the following versions of '#{name}': #{formatted_versions_with_platforms(versions_with_platforms)}" if versions_with_platforms.any?
         end
         raise GemNotFound, message
@@ -371,7 +371,7 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/resolver.rb#L371
             o << if metadata_requirement
               "is not available in #{relevant_source}"
             else
-              "in #{relevant_source}.\n"
+              "in #{relevant_source.to_err}.\n"
             end
           end
         end,
diff --git a/lib/bundler/source.rb b/lib/bundler/source.rb
index 5388a76..434112a 100644
--- a/lib/bundler/source.rb
+++ b/lib/bundler/source.rb
@@ -67,6 +67,10 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source.rb#L67
       "#<#{self.class}:0x#{object_id} #{self}>"
     end
 
+    def to_err
+      to_s
+    end
+
     def path?
       instance_of?(Bundler::Source::Path)
     end
diff --git a/lib/bundler/source/rubygems.rb b/lib/bundler/source/rubygems.rb
index 858a69a..6728ffd 100644
--- a/lib/bundler/source/rubygems.rb
+++ b/lib/bundler/source/rubygems.rb
@@ -96,11 +96,22 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source/rubygems.rb#L96
         out << "  specs:\n"
       end
 
+      def to_err
+        if remotes.empty?
+          "locally installed gems"
+        elsif @allow_remote
+          "rubygems repository #{remote_names} or installed locally"
+        elsif @allow_cached
+          "cached gems from rubygems repository #{remote_names} or installed locally"
+        else
+          "locally installed gems"
+        end
+      end
+
       def to_s
         if remotes.empty?
           "locally installed gems"
         else
-          remote_names = remotes.map(&:to_s).join(", ")
           "rubygems repository #{remote_names} or installed locally"
         end
       end
@@ -319,6 +330,10 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source/rubygems.rb#L330
 
       protected
 
+      def remote_names
+        remotes.map(&:to_s).join(", ")
+      end
+
       def credless_remotes
         remotes.map(&method(:suppress_configured_credentials))
       end
diff --git a/lib/bundler/source/rubygems_aggregate.rb b/lib/bundler/source/rubygems_aggregate.rb
index 685bf7e..09cf400 100644
--- a/lib/bundler/source/rubygems_aggregate.rb
+++ b/lib/bundler/source/rubygems_aggregate.rb
@@ -16,6 +16,10 @@ module Bundler https://github.com/ruby/ruby/blob/trunk/lib/bundler/source/rubygems_aggregate.rb#L16
         @index
       end
 
+      def to_err
+        to_s
+      end
+
       def to_s
         "any of the sources"
       end
diff --git a/spec/bundler/commands/exec_spec.rb b/spec/bundler/commands/exec_spec.rb
index 68c4726..c6648f0 100644
--- a/spec/bundler/commands/exec_spec.rb
+++ b/spec/bundler/commands/exec_spec.rb
@@ -836,7 +836,7 @@ RSpec.describe "bundle exec" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/exec_spec.rb#L836
       let(:exit_code) { Bundler::GemNotFound.new.status_code }
       let(:expected) { "" }
       let(:expected_err) { <<-EOS.strip }
-Could not find gem 'rack (= 2)' in rubygems repository #{file_uri_for(gem_repo1)}/ or installed locally.
+Could not find gem 'rack (= 2)' in locally installed gems.
 The source contains the following versions of 'rack': 0.9.1, 1.0.0
 Run `bundle install` to install missing gems.
       EOS
@@ -863,7 +863,7 @@ Run `bundle install` to install missing gems. https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/exec_spec.rb#L863
       let(:exit_code) { Bundler::GemNotFound.new.status_code }
       let(:expected) { "" }
       let(:expected_err) { <<-EOS.strip }
-Could not find gem 'rack (= 2)' in rubygems repository #{file_uri_for(gem_repo1)}/ or installed locally.
+Could not find gem 'rack (= 2)' in locally installed gems.
 The source contains the following versions of 'rack': 1.0.0
 Run `bundle install` to install missing gems.
       EOS
diff --git a/spec/bundler/commands/lock_spec.rb b/spec/bundler/commands/lock_spec.rb
index 21eb6e5..171ec1b 100644
--- a/spec/bundler/commands/lock_spec.rb
+++ b/spec/bundler/commands/lock_spec.rb
@@ -86,7 +86,7 @@ RSpec.describe "bundle lock" do https://github.com/ruby/ruby/blob/trunk/spec/bundler/commands/lock_spec.rb#L86
   it "does not fetch remote specs when using the --local option" do
     bundle "lock --update --local", :raise_on_error => false
 
-    expect(err).to match(/installed locally/)
+    expect(err).to match(/locally installed gems/)
   end
 
   it "works with --gemfile flag" do
diff --git a/spec/bundler/support/indexes.rb b/spec/bundler/support/indexes.rb
index bf4300e..91dd699 100644
--- a/spec/bundler/support/indexes.rb
+++ b/spec/bundler/support/indexes.rb
@@ -17,7 +17,7 @@ module Spec https://github.com/ruby/ruby/blob/trunk/spec/bundler/support/indexes.rb#L17
     def resolve(args = [])
       @platforms ||= ["ruby"]
       deps = []
-      default_source = instance_double("Bundler::Source::Rubygems", :specs => @index)
+      default_source = instance_double("Bundler::Source::Rubygems", :specs => @index, :to_err => "locally install gems")
       source_requirements = { :default => default_source }
       @deps.each do |d|
         source_requirements[d.name] = d.source = default_source
-- 
cgit v1.1


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

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