Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Commit

Permalink
Auto merge of #5336 - bundler:seg-installation-failure-reason, r=indi…
Browse files Browse the repository at this point in the history
…rect

[ParallelInstaller] Print out why a gem needed to be installed if ins…

…tallation fails

I think this will close #5078 by making it easier to understand why a gem needed to be installed, especially in the case when the user can't just look in the lockfile
  • Loading branch information
bundlerbot committed Feb 21, 2017
2 parents c73088d + bc95fde commit 4a60a49
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
16 changes: 15 additions & 1 deletion lib/bundler/installer/parallel_installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def initialize(installer, all_specs, size, standalone, force)
@standalone = standalone
@force = force
@specs = all_specs.map {|s| SpecInstallation.new(s) }
@spec_set = all_specs
end

def call
Expand All @@ -116,7 +117,7 @@ def worker_pool
spec_install.post_install_message = message
elsif !success
spec_install.state = :failed
spec_install.error = message
spec_install.error = "#{message}\n\n#{require_tree_for_spec(spec_install.spec)}"
end
spec_install
}
Expand Down Expand Up @@ -166,6 +167,19 @@ def check_for_corrupt_lockfile
Bundler.ui.warn(warning.join("\n"))
end

def require_tree_for_spec(spec)
tree = @spec_set.what_required(spec)
t = String.new("In #{File.basename(SharedHelpers.default_gemfile)}:\n")
tree.each_with_index do |s, depth|
t << " " * depth.succ << s.name
unless tree.last == s
t << %( was resolved to #{s.version}, which depends on)
end
t << %(\n)
end
t
end

# Keys in the remains hash represent uninstalled gems specs.
# We enqueue all gem specs that do not have any dependencies.
# Later we call this lambda again to install specs that depended on
Expand Down
7 changes: 7 additions & 0 deletions lib/bundler/spec_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ def find_by_name_and_platform(name, platform)
@specs.detect {|spec| spec.name == name && spec.match_platform(platform) }
end

def what_required(spec)
unless req = find {|s| s.dependencies.any? {|d| d.type == :runtime && d.name == spec.name } }
return [spec]
end
what_required(req) << spec
end

private

def sorted
Expand Down
33 changes: 33 additions & 0 deletions spec/install/failure_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# frozen_string_literal: true
require "spec_helper"

RSpec.describe "bundle install" do
context "installing a gem fails" do
it "prints out why that gem was being installed" do
build_repo2 do
build_gem "activesupport", "2.3.2" do |s|
s.extensions << "Rakefile"
s.write "Rakefile", <<-RUBY
task :default do
abort "make installing activesupport-2.3.2 fail"
end
RUBY
end
end

install_gemfile <<-G
source "file:#{gem_repo2}"
gem "rails"
G
expect(out).to end_with(<<-M.strip)
An error occurred while installing activesupport (2.3.2), and Bundler cannot continue.
Make sure that `gem install activesupport -v '2.3.2'` succeeds before bundling.
In Gemfile:
rails was resolved to 2.3.2, which depends on
actionmailer was resolved to 2.3.2, which depends on
activesupport
M
end
end
end
7 changes: 6 additions & 1 deletion spec/install/gemfile/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,12 @@
gem "foo", :git => "#{lib_path("foo-1.0")}"
G

expect(out).to include("An error occurred while installing foo (1.0)")
expect(out).to end_with(<<-M.strip)
An error occurred while installing foo (1.0), and Bundler cannot continue.
In Gemfile:
foo
M
expect(out).not_to include("gem install foo")
end

Expand Down

0 comments on commit 4a60a49

Please sign in to comment.