Skip to content

Commit

Permalink
Handle TapFormulaAmbiguityError in diagnostics.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Feb 14, 2024
1 parent 9056613 commit ce60048
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
8 changes: 7 additions & 1 deletion Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions Library/Homebrew/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ce60048

Please sign in to comment.