named_args: raise rescued error if both formula/cask are unreadable

This commit is contained in:
Seeker 2021-01-27 10:02:07 -08:00
parent db6f65ddc0
commit 89930157b5
2 changed files with 5 additions and 5 deletions

View File

@ -78,7 +78,7 @@ module Homebrew
end
def load_formula_or_cask(name, only: nil, method: nil)
unreadable_errors = []
unreadable_error = nil
if only != :cask
begin
@ -102,7 +102,7 @@ module Homebrew
TapFormulaUnreadableError, TapFormulaClassUnavailableError => e
# Need to rescue before `FormulaUnavailableError` (superclass of this)
# The formula was found, but there's a problem with its implementation
unreadable_errors << e
unreadable_error ||= e
rescue NoSuchKegError, FormulaUnavailableError => e
raise e if only == :formula
end
@ -114,13 +114,13 @@ module Homebrew
rescue Cask::CaskUnreadableError => e
# Need to rescue before `CaskUnavailableError` (superclass of this)
# The cask was found, but there's a problem with its implementation
unreadable_errors << e
unreadable_error ||= e
rescue Cask::CaskUnavailableError => e
raise e if only == :cask
end
end
raise unreadable_errors.first if unreadable_errors.count == 1
raise unreadable_error if unreadable_error.present?
raise FormulaOrCaskUnavailableError, name
end

View File

@ -99,7 +99,7 @@ describe Homebrew::CLI::NamedArgs do
end
it "raises an error" do
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaOrCaskUnavailableError)
expect { described_class.new("foo").to_formulae_and_casks }.to raise_error(FormulaUnreadableError)
end
it "raises an error if loading formula only" do