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

Commit

Permalink
Add error messages when gems are missing during resolve time
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehuda Katz + Carl Lerche committed Aug 18, 2009
1 parent ed2cfc6 commit d739dbc
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/bundler/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def self.run(command, options = {})
rescue VersionConflict => e
Bundler.logger.error e.message
exit
rescue GemNotFound => e
Bundler.logger.error e.message
exit
end

def initialize(options)
Expand Down
8 changes: 8 additions & 0 deletions lib/bundler/resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def required_by
end

module Bundler
class GemNotFound < StandardError; end

class Resolver

Expand Down Expand Up @@ -100,6 +101,13 @@ def resolve(reqs, activated)
# TODO: Warn / error when no matching versions are found.
matching_versions = @index.search(current)

if matching_versions.empty?
if current.required_by.empty?
raise GemNotFound, "Could not find gem '#{current}' in any of the sources"
end
Bundler.logger.warn "Could not find gem '#{current}' (required by '#{current.required_by.last}') in any of the sources"
end

matching_versions.reverse_each do |spec|
conflict = resolve_requirement(spec, current, reqs.dup, activated.dup)
conflicts << conflict if conflict
Expand Down
26 changes: 26 additions & 0 deletions spec/bundler/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,36 @@
end

describe "error cases" do
before(:each) do
Dir.chdir(tmp_dir)
end

it "displays a friendly error message when there is no Gemfile" do
out = gem_command :bundle
out.should == "Could not find a Gemfile to use"
end

it "fails when a root level gem does not exist" do
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "monk"
Gemfile

out = gem_command :bundle
out.should include("Could not find gem 'monk (>= 0, runtime)' in any of the sources")
end

it "outputs a warning when a child gem dependency is missing dependencies" do
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
gem "treetop"
Gemfile

out = gem_command :bundle
out.should include("Could not find gem 'polyglot (>= 0.2.5, runtime)' (required by 'treetop (>= 0, runtime)') in any of the sources")
end
end

describe "it working while specifying the manifest file name" do
Expand Down
1 change: 1 addition & 0 deletions spec/bundler/manifest_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def dep(name, version, options = {})
end

it "raises a friendly exception if the manifest doesn't resolve" do
pending
build_manifest <<-Gemfile
clear_sources
source "file://#{gem_repo1}"
Expand Down
2 changes: 1 addition & 1 deletion spec/resolver/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,6 @@
build_dep("a", "= 1.1"),
]

Bundler::Resolver.resolve(deps, index).should be_nil
lambda { Bundler::Resolver.resolve(deps, index) }.should raise_error(Bundler::GemNotFound)
end
end

0 comments on commit d739dbc

Please sign in to comment.