[rubygems/rubygems] Improve error message when strict resolution filters out everything

https://github.com/rubygems/rubygems/commit/1ea44b3749
This commit is contained in:
David Rodriguez 2024-03-21 20:59:42 +01:00 committed by git
parent f80bb3837c
commit e2a1d0b53d
2 changed files with 36 additions and 0 deletions

View File

@ -342,6 +342,17 @@ module Bundler
@gem_version_promoter.filter_versions(package, @all_versions[package])
end
def raise_all_versions_filtered_out!(package)
level = @gem_version_promoter.level
name = package.name
locked_version = package.locked_version
requirement = package.dependency
raise GemNotFound,
"#{name} is locked to #{locked_version}, while Gemfile is requesting #{requirement}. " \
"--strict --#{level} was specified, but there are no #{level} level upgrades from #{locked_version} satisfying #{requirement}, so version solving has failed"
end
def filter_matching_specs(specs, requirements)
Array(requirements).flat_map do |requirement|
specs.select {| spec| requirement_satisfied_by?(requirement, spec) }
@ -391,6 +402,11 @@ module Bundler
dep_package.consider_prereleases!
versions = select_sorted_versions(dep_package, dep_range)
end
if versions.empty? && select_all_versions(dep_package, dep_range).any?
raise_all_versions_filtered_out!(dep_package)
end
next [dep_package, dep_constraint] unless versions.empty?
next unless dep_package.current_platform?
@ -403,6 +419,10 @@ module Bundler
range.select_versions(@sorted_versions[package])
end
def select_all_versions(package, range)
range.select_versions(@all_versions[package])
end
def other_specs_matching_message(specs, requirement)
message = String.new("The source contains the following gems matching '#{requirement}':\n")
message << specs.map {|s| " * #{s.full_name}" }.join("\n")

View File

@ -392,6 +392,22 @@ RSpec.describe "bundle lock" do
expect(the_bundle.locked_gems.specs.map(&:full_name)).to eq(%w[foo-1.5.0 bar-2.1.1 qux-1.1.0].sort)
end
it "shows proper error when Gemfile changes forbid patch upgrades, and --patch --strict is given" do
# force next minor via Gemfile
gemfile <<-G
source "#{file_uri_for(gem_repo4)}"
gem 'foo', '1.5.0'
gem 'qux'
G
bundle "lock --update foo --patch --strict", raise_on_error: false
expect(err).to include(
"foo is locked to 1.4.3, while Gemfile is requesting foo (= 1.5.0). " \
"--strict --patch was specified, but there are no patch level upgrades from 1.4.3 satisfying foo (= 1.5.0), so version solving has failed"
)
end
context "pre" do
it "defaults to major" do
bundle "lock --update --pre"