mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[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.
30eb14f853
This commit is contained in:
parent
2e850e0038
commit
0b4dbe2e6a
Notes:
git
2021-08-31 19:07:20 +09:00
7 changed files with 30 additions and 7 deletions
|
@ -272,7 +272,7 @@ module Bundler
|
|||
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
|
|||
o << if metadata_requirement
|
||||
"is not available in #{relevant_source}"
|
||||
else
|
||||
"in #{relevant_source}.\n"
|
||||
"in #{relevant_source.to_err}.\n"
|
||||
end
|
||||
end
|
||||
end,
|
||||
|
|
|
@ -67,6 +67,10 @@ module Bundler
|
|||
"#<#{self.class}:0x#{object_id} #{self}>"
|
||||
end
|
||||
|
||||
def to_err
|
||||
to_s
|
||||
end
|
||||
|
||||
def path?
|
||||
instance_of?(Bundler::Source::Path)
|
||||
end
|
||||
|
|
|
@ -96,11 +96,22 @@ module Bundler
|
|||
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
|
|||
|
||||
protected
|
||||
|
||||
def remote_names
|
||||
remotes.map(&:to_s).join(", ")
|
||||
end
|
||||
|
||||
def credless_remotes
|
||||
remotes.map(&method(:suppress_configured_credentials))
|
||||
end
|
||||
|
|
|
@ -16,6 +16,10 @@ module Bundler
|
|||
@index
|
||||
end
|
||||
|
||||
def to_err
|
||||
to_s
|
||||
end
|
||||
|
||||
def to_s
|
||||
"any of the sources"
|
||||
end
|
||||
|
|
|
@ -836,7 +836,7 @@ RSpec.describe "bundle exec" do
|
|||
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.
|
|||
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
|
||||
|
|
|
@ -86,7 +86,7 @@ RSpec.describe "bundle lock" do
|
|||
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
|
||||
|
|
|
@ -17,7 +17,7 @@ module Spec
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue