Skip to content

Commit

Permalink
Improve the error message when no gem is found due to platform mismat…
Browse files Browse the repository at this point in the history
…ches
  • Loading branch information
evanphx committed Oct 21, 2013
1 parent 9680862 commit a0f0de7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
17 changes: 5 additions & 12 deletions lib/rubygems/dependency_resolver.rb
Expand Up @@ -118,14 +118,6 @@ def find_conflict_state conflict, states # :nodoc:
states.replace rejected
end

##
# Extracts the specifications that may be able to fulfill +dependency+

def find_possible dependency # :nodoc:
possible = @set.find_all dependency
select_local_platforms possible
end

def handle_conflict(dep, existing)
# There is a conflict! We return the conflict object which will be seen by
# the caller and be handled at the right level.
Expand Down Expand Up @@ -189,11 +181,12 @@ def resolve_for needed, specs
next
end

possible = find_possible dep
all_possible = @set.find_all dep
possible = select_local_platforms all_possible

case possible.size
when 0
resolve_for_zero dep
resolve_for_zero dep, all_possible
when 1
needed, specs =
resolve_for_single needed, specs, dep, possible
Expand Down Expand Up @@ -282,11 +275,11 @@ def resolve_for_single needed, specs, dep, possible # :nodoc:
##
# When there are no possible specifications for +dep+ our work is done.

def resolve_for_zero dep # :nodoc:
def resolve_for_zero dep, platform_mismatch # :nodoc:
@missing << dep

unless @soft_missing
raise Gem::UnsatisfiableDependencyError, dep
raise Gem::UnsatisfiableDependencyError.new(dep, platform_mismatch)
end
end

Expand Down
13 changes: 9 additions & 4 deletions lib/rubygems/exceptions.rb
Expand Up @@ -226,10 +226,15 @@ class Gem::UnsatisfiableDependencyError < Gem::Exception
# Creates a new UnsatisfiableDepedencyError for the unsatisfiable
# Gem::DependencyResolver::DependencyRequest +dep+

def initialize dep
requester = dep.requester ? dep.requester.request : '(unknown)'

super "Unable to resolve dependency: #{requester} requires #{dep}"
def initialize dep, platform_mismatch=nil
if platform_mismatch and !platform_mismatch.empty?
plats = platform_mismatch.map { |x| x.platform.to_s }.sort.uniq
super "Unable to resolve dependency: No match for '#{dep}' on this platform. Found: #{plats.join(', ')}"
else
requester = dep.requester ? dep.requester.request : '(unknown)'

super "Unable to resolve dependency: #{requester} requires #{dep}"
end

@dependency = dep
end
Expand Down
16 changes: 16 additions & 0 deletions test/rubygems/test_gem_dependency_resolver.rb
Expand Up @@ -408,5 +408,21 @@ def test_select_local_platforms
assert_equal [a1, a1_p1], selected
end

def test_raises_and_explains_when_platform_prevents_install
a1 = util_spec "a", "1" do |s|
s.platform = Gem::Platform.new %w[c p 1]
end

ad = make_dep "a", "= 1"

r = Gem::DependencyResolver.new([ad], set(a1))

e = assert_raises Gem::UnsatisfiableDepedencyError do
r.resolve
end

assert_match /No match for 'a \(= 1\)' on this platform. Found: c-p-1/, e.message
end

end

0 comments on commit a0f0de7

Please sign in to comment.