Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pretty error from Bundle.setup when gems are missing

  • Loading branch information...
commit 1f84fd9c18150606d9e5d28cb267b7594809f6ff 1 parent 4754b36
@indirect indirect authored
Showing with 34 additions and 18 deletions.
  1. +16 −10 lib/bundler.rb
  2. +1 −1  lib/bundler/runtime.rb
  3. +17 −7 spec/runtime/setup_spec.rb
View
26 lib/bundler.rb
@@ -69,16 +69,22 @@ def bundle_path
def setup(*groups)
return @setup if @setup
- if groups.empty?
- # Load all groups, but only once
- @setup = load.setup
- else
- # Figure out which groups haven't been loaded yet
- unloaded = groups - (@completed_groups || [])
- # Record groups that are now loaded
- @completed_groups = groups | (@completed_groups || [])
- # Load any groups that are not yet loaded
- unloaded.any? ? load.setup(*unloaded) : load
+ begin
+ if groups.empty?
+ # Load all groups, but only once
+ @setup = load.setup
+ else
+ # Figure out which groups haven't been loaded yet
+ unloaded = groups - (@completed_groups || [])
+ # Record groups that are now loaded
+ @completed_groups = groups | (@completed_groups || [])
+ # Load any groups that are not yet loaded
+ unloaded.any? ? load.setup(*unloaded) : load
+ end
+ rescue Bundler::GemNotFound => e
+ STDERR.puts e.message
+ STDERR.puts "Try running `bundle install`."
+ exit!
end
end
View
2  lib/bundler/runtime.rb
@@ -23,7 +23,7 @@ def setup(*groups)
# Activate the specs
specs.each do |spec|
unless spec.loaded_from
- raise GemNotFound, "#{spec.full_name} is not installed. Try running `bundle install`."
+ raise GemNotFound, "#{spec.full_name} is cached, but not installed."
end
Gem.loaded_specs[spec.name] = spec
View
24 spec/runtime/setup_spec.rb
@@ -145,17 +145,14 @@
gem "rack"
G
- ruby <<-R
+ ruby <<-R, :expect_err => true
require 'rubygems'
require 'bundler'
- begin
- Bundler.setup
- rescue Bundler::BundlerError => e
- puts e.message
- end
+ Bundler.setup
R
- out.should == "rack-1.0 is not installed. Try running `bundle install`."
+ err.should include("rack-1.0 is cached, but not installed")
+ err.should include("Try running `bundle install`.")
end
end
@@ -242,4 +239,17 @@
err.should be_empty
end
+ it "doesn't throw a backtrace when gems are missing" do
+ gemfile <<-G
+ source "file://#{gem_repo1}"
+ gem "imaginary"
+ G
+ run <<-R, :expect_err => true
+ Bundler.setup
+ R
+
+ err.should include"Could not find gem 'imaginary")
+ err.should include("Try running `bundle install`")
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.