Skip to content

Commit

Permalink
Improve resolver error messages
Browse files Browse the repository at this point in the history
Use a more standard naming for gems.
  • Loading branch information
deivid-rodriguez committed Dec 15, 2021
1 parent e360e8a commit 75121e8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 18 deletions.
14 changes: 1 addition & 13 deletions bundler/lib/bundler/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,30 +264,18 @@ def verify_gemfile_dependencies_are_found!(requirements)
else
source = source_for(name)
specs = source.specs.search(name)
versions_with_platforms = specs.map {|s| [s.version, s.platform] }
cache_message = begin
" or in gems cached in #{Bundler.settings.app_cache_path}" if Bundler.app_cache.exist?
rescue GemfileNotFound
nil
end
message = String.new("Could not find gem '#{SharedHelpers.pretty_dependency(requirement)}' in #{source}#{cache_message}.\n")
message << "The source contains the following versions of '#{name}': #{formatted_versions_with_platforms(versions_with_platforms)}" if versions_with_platforms.any?
message << "The source contains the following gems matching '#{name}': #{specs.map(&:full_name).join(", ")}" if specs.any?
end
raise GemNotFound, message
end
end

def formatted_versions_with_platforms(versions_with_platforms)
version_platform_strs = versions_with_platforms.map do |vwp|
version = vwp.first
platform = vwp.last
version_platform_str = String.new(version.to_s)
version_platform_str << " #{platform}" unless platform.nil? || platform == Gem::Platform::RUBY
version_platform_str
end
version_platform_strs.join(", ")
end

def version_conflict_message(e)
# only show essential conflicts, if possible
conflicts = e.conflicts.dup
Expand Down
4 changes: 2 additions & 2 deletions bundler/spec/commands/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ def bin_path(a,b,c)
let(:expected) { "" }
let(:expected_err) { <<-EOS.strip }
Could not find gem 'rack (= 2)' in locally installed gems.
The source contains the following versions of 'rack': 0.9.1, 1.0.0
The source contains the following gems matching 'rack': rack-0.9.1, rack-1.0.0
Run `bundle install` to install missing gems.
EOS

Expand All @@ -894,7 +894,7 @@ def bin_path(a,b,c)
let(:expected) { "" }
let(:expected_err) { <<-EOS.strip }
Could not find gem 'rack (= 2)' in locally installed gems.
The source contains the following versions of 'rack': 1.0.0
The source contains the following gems matching 'rack': rack-1.0.0
Run `bundle install` to install missing gems.
EOS

Expand Down
6 changes: 3 additions & 3 deletions bundler/spec/install/gemfile/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
gem "foo", "1.1", :git => "#{lib_path("foo-1.0")}"
G

expect(err).to include("The source contains the following versions of 'foo': 1.0")
expect(err).to include("The source contains the following gems matching 'foo': foo-1.0")
end

it "complains with version and platform if pinned specs don't exist in the git repo" do
Expand All @@ -106,7 +106,7 @@
end
G

expect(err).to include("The source contains the following versions of 'only_java': 1.0 java")
expect(err).to include("The source contains the following gems matching 'only_java': only_java-1.0-java")
end

it "complains with multiple versions and platforms if pinned specs don't exist in the git repo" do
Expand All @@ -128,7 +128,7 @@
end
G

expect(err).to include("The source contains the following versions of 'only_java': 1.0 java, 1.1 java")
expect(err).to include("The source contains the following gems matching 'only_java': only_java-1.0-java, only_java-1.1-java")
end

it "still works after moving the application directory" do
Expand Down

0 comments on commit 75121e8

Please sign in to comment.