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

Commit

Permalink
Pretty error from Bundle.setup when gems are missing
Browse files Browse the repository at this point in the history
  • Loading branch information
indirect committed Apr 14, 2010
1 parent 4754b36 commit 1f84fd9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
26 changes: 16 additions & 10 deletions lib/bundler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/bundler/runtime.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 17 additions & 7 deletions spec/runtime/setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

0 comments on commit 1f84fd9

Please sign in to comment.