From 501fecb264ce104ae90560787f2d847bc52db626 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 7 May 2026 19:11:57 +0900 Subject: [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) --- lib/bundler/resolver.rb | 16 ++++++++++++++++ spec/bundler/install/gemfile/override_spec.rb | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) 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 -- cgit v1.2.3