summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2016-06-08 01:40:23 -0500
committerSamuel Giddins <segiddins@segiddins.me>2016-06-10 01:42:17 -0500
commit848d33ca47805fd6817cc301dc82ac1bc3924046 (patch)
treee7e23ad78cf65d54e7612213e459df5cf80b39aa
parentd61ab01f5a5370a6873130c13272c515fa76b6af (diff)
downloadbundler-848d33ca47805fd6817cc301dc82ac1bc3924046.tar.gz
Fail gracefully when installing bundler fails
-rw-r--r--lib/bundler/postit_trampoline.rb12
-rw-r--r--spec/other/trampoline_spec.rb10
2 files changed, 20 insertions, 2 deletions
diff --git a/lib/bundler/postit_trampoline.rb b/lib/bundler/postit_trampoline.rb
index f648832202..7406612e5b 100644
--- a/lib/bundler/postit_trampoline.rb
+++ b/lib/bundler/postit_trampoline.rb
@@ -18,8 +18,16 @@ installed_version =
installed_version &&= Gem::Version.new(installed_version)
if !version.satisfied_by?(installed_version)
- installer = BundlerVendoredPostIt::Installer.new(version)
- installer.install!
+ begin
+ installer = BundlerVendoredPostIt::Installer.new(version)
+ installer.install!
+ rescue => e
+ abort <<-EOS.strip
+Installing the inferred bundler version (#{version}) failed.
+If you'd like to update to the current bundler version (#{installed_version}) in this project, run `bundle update --bundler`.
+The error was: #{e}
+ EOS
+ end
Gem.loaded_specs.delete("bundler") unless defined?(Bundler)
gem "bundler", version
diff --git a/spec/other/trampoline_spec.rb b/spec/other/trampoline_spec.rb
index 9a76819f8f..41a06c5125 100644
--- a/spec/other/trampoline_spec.rb
+++ b/spec/other/trampoline_spec.rb
@@ -69,6 +69,16 @@ describe "bundler version trampolining" do
expect(out).to eq("Bundler version 1.12.3")
expect(system_gem_path.join("gems", "bundler-1.12.3")).to exist
end
+
+ it "fails gracefully when installing the bundler fails" do
+ ENV["BUNDLER_VERSION"] = "9999"
+ bundle "--version", :expect_err => true
+ expect(err).to eq(<<-E.strip)
+Installing the inferred bundler version (= 9999) failed.
+If you'd like to update to the current bundler version (1.12.5) in this project, run `bundle update --bundler`.
+The error was: Unable to resolve dependency: user requested 'bundler (= 9999)'
+ E
+ end
end
context "bundle update --bundler" do