From ce60048192d7f2a5b04cd44d4ca28325a5c1e390 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Wed, 14 Feb 2024 20:27:53 +0100 Subject: [PATCH] Handle `TapFormulaAmbiguityError` in diagnostics. --- Library/Homebrew/diagnostic.rb | 8 +++++++- Library/Homebrew/exceptions.rb | 7 ++++--- Library/Homebrew/formulary.rb | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index b869809a0612e..87d58992598f5 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -841,7 +841,13 @@ def check_deleted_formula Formulary::FromAPILoader, Formulary::FromNameLoader, ].any? do |loader_class| - if (loader = loader_class.try_new(keg.name, warn: false)) + loader = begin + loader_class.try_new(keg.name, warn: false) + rescue TapFormulaAmbiguityError => e + e.loaders.first + end + + if loader # If we know the tap, ignore all other taps. next false if tap && loader.tap != tap diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index e402a3b8280a6..3fdda640b25c1 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -259,11 +259,12 @@ def initialize(tap, name, error) # Raised when a formula with the same name is found in multiple taps. class TapFormulaAmbiguityError < RuntimeError - attr_reader :name, :taps + attr_reader :name, :taps, :loaders - def initialize(name, taps) + def initialize(name, loaders) @name = name - @taps = taps + @loaders = loaders + @taps = loaders.map(&:tap) formulae = taps.map { |tap| "#{tap}/#{name}" } formula_list = formulae.map { |f| "\n * #{f}" }.join diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 87a399b4e6e56..4e7f151c8b3a8 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -772,7 +772,7 @@ def self.try_new(ref, from: T.unsafe(nil), warn: false) when 1 loaders.first when 2..Float::INFINITY - raise TapFormulaAmbiguityError.new(name, loaders.map(&:tap)) + raise TapFormulaAmbiguityError.new(name, loaders) end end end