Skip to content

Commit

Permalink
Improve errors a bit more
Browse files Browse the repository at this point in the history
  • Loading branch information
deivid-rodriguez committed Dec 15, 2021
1 parent e4a1a96 commit f481e8f
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
7 changes: 6 additions & 1 deletion bundler/lib/bundler/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,12 @@ def gem_not_found_message(name, requirement, source, extra_message = "")
end

message = String.new("Could not find gem '#{requirement_label}'#{extra_message} in #{source}#{cache_message}.\n")
message << "The source contains the following gems matching '#{matching_part}': #{specs.map(&:full_name).join(", ")}" if specs.any?

if specs.any?
message << "\nThe source contains the following gems matching '#{matching_part}':\n"
message << specs.map {|s| " * #{s.full_name}" }.join("\n")
end

message
end

Expand Down
9 changes: 7 additions & 2 deletions bundler/spec/commands/exec_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,10 @@ 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 gems matching 'rack': rack-0.9.1, rack-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 +897,9 @@ 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 gems matching 'rack': 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 gems matching 'foo': foo-1.0")
expect(err).to include("The source contains the following gems matching 'foo':\n * 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 gems matching 'only_java': only_java-1.0-java")
expect(err).to include("The source contains the following gems matching 'only_java':\n * 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 gems matching 'only_java': only_java-1.0-java, only_java-1.1-java")
expect(err).to include("The source contains the following gems matching 'only_java':\n * only_java-1.0-java\n * only_java-1.1-java")
end

it "still works after moving the application directory" do
Expand Down
18 changes: 14 additions & 4 deletions bundler/spec/install/gemfile/specific_platform_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,13 @@
bundle "install", :raise_on_error => false
end

expect(err).to include("Could not find gem 'sorbet-static (= 0.5.6433) arm64-darwin-21' in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally.")
expect(err).to include("The source contains the following gems matching 'sorbet-static (= 0.5.6433)': sorbet-static-0.5.6433-universal-darwin-20, sorbet-static-0.5.6433-x86_64-linux")
expect(err).to include <<~ERROR.rstrip
Could not find gem 'sorbet-static (= 0.5.6433) arm64-darwin-21' in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally.
The source contains the following gems matching 'sorbet-static (= 0.5.6433)':
* sorbet-static-0.5.6433-universal-darwin-20
* sorbet-static-0.5.6433-x86_64-linux
ERROR
end

it "does not resolve if the current platform does not match any of available platform specific variants for a transitive dependency" do
Expand All @@ -319,8 +324,13 @@
bundle "install", :raise_on_error => false
end

expect(err).to include("Could not find gem 'sorbet-static (= 0.5.6433) arm64-darwin-21', which is required by gem 'sorbet (= 0.5.6433)', in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally.")
expect(err).to include("The source contains the following gems matching 'sorbet-static (= 0.5.6433)': sorbet-static-0.5.6433-universal-darwin-20, sorbet-static-0.5.6433-x86_64-linux")
expect(err).to include <<~ERROR.rstrip
Could not find gem 'sorbet-static (= 0.5.6433) arm64-darwin-21', which is required by gem 'sorbet (= 0.5.6433)', in rubygems repository #{file_uri_for(gem_repo2)}/ or installed locally.
The source contains the following gems matching 'sorbet-static (= 0.5.6433)':
* sorbet-static-0.5.6433-universal-darwin-20
* sorbet-static-0.5.6433-x86_64-linux
ERROR
end

private
Expand Down

0 comments on commit f481e8f

Please sign in to comment.