summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2026-05-07 19:11:57 +0900
committergit <svn-admin@ruby-lang.org>2026-05-08 06:43:44 +0000
commit501fecb264ce104ae90560787f2d847bc52db626 (patch)
tree05e41fb0b6934ffdc42c54a5205df4ef16be5e10
parentf451ea9c9f8c5d11798cdd1ecf8f8865cd3654d2 (diff)
[ruby/rubygems] Show active overrides when resolution fails
Append the list of currently active overrides (with Gemfile location, when known) to the SolveFailure message so a user investigating a "could not find compatible versions" error sees what override changed the constraint set instead of being misled by the resolver-reported requirement. https://github.com/ruby/rubygems/commit/10b8b53270 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
-rw-r--r--lib/bundler/resolver.rb16
-rw-r--r--spec/bundler/install/gemfile/override_spec.rb21
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/bundler/resolver.rb b/lib/bundler/resolver.rb
index 5b575f15e6..fb69becd69 100644
--- a/lib/bundler/resolver.rb
+++ b/lib/bundler/resolver.rb
@@ -122,9 +122,25 @@ module Bundler
explanation << extended_explanation
end
+ override_summary = override_diagnostic_summary
+ explanation << override_summary if override_summary
+
raise SolveFailure.new(explanation)
end
+ def override_diagnostic_summary
+ return nil if @base.overrides.empty?
+
+ lines = ["Bundler applied the following overrides while resolving:"]
+ @base.overrides.each do |override|
+ target = override.target == :all ? ":all" : override.target.inspect
+ location = override.source_location_label
+ lines << " override #{target}, #{override.field}: #{override.operation.inspect}" \
+ "#{location ? " (declared at #{location})" : ""}"
+ end
+ "\n\n#{lines.join("\n")}"
+ end
+
def find_names_to_relax(incompatibility)
names_to_unlock = []
names_to_allow_prereleases_for = []
diff --git a/spec/bundler/install/gemfile/override_spec.rb b/spec/bundler/install/gemfile/override_spec.rb
index 54dd031853..19fa2ee915 100644
--- a/spec/bundler/install/gemfile/override_spec.rb
+++ b/spec/bundler/install/gemfile/override_spec.rb
@@ -318,6 +318,27 @@ RSpec.describe "override DSL" do
end
end
+ context "diagnostic on resolve failure" do
+ it "lists active overrides with their Gemfile location" do
+ build_repo2 do
+ build_gem "needs_old_ruby", "1.0" do |s|
+ s.required_ruby_version = "= #{Gem.ruby_version}.999"
+ end
+ end
+
+ gemfile <<-G
+ source "https://gem.repo2"
+ override "needs_old_ruby", required_ruby_version: "= #{Gem.ruby_version}.999"
+ gem "needs_old_ruby"
+ G
+
+ bundle :lock, raise_on_error: false
+ expect(err).to include("Bundler applied the following overrides")
+ expect(err).to include("override \"needs_old_ruby\", required_ruby_version:")
+ expect(err).to match(/declared at Gemfile:\d+/)
+ end
+ end
+
context "install-time compatibility" do
it "installs a gem whose required_ruby_version excludes the current Ruby when an override removes the constraint" do
build_repo2 do