Fix error message duplication for installation from URL

This commit is contained in:
Alexander Bayandin 2021-12-02 15:53:09 +00:00
parent 120dab2816
commit 7fb74cb1dc
No known key found for this signature in database
GPG Key ID: 444BD9CA93262701
2 changed files with 9 additions and 5 deletions

View File

@ -45,6 +45,8 @@ class KegUnspecifiedError < UsageError
end
end
class UnsupportedInstallationMethod < RuntimeError; end
class MultipleVersionsInstalledError < RuntimeError; end
class NotAKegError < RuntimeError; end

View File

@ -274,12 +274,14 @@ module Formulary
def load_file(flags:, ignore_errors:)
if %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(?:/Formula)?/(?<formula_name>[\w+-.@]+).rb} =~ url
raise UsageError, "Installation of #{formula_name} from a GitHub commit URL is unsupported! " \
"`brew extract #{formula_name}` to a stable tap on GitHub instead."
raise UnsupportedInstallationMethod,
"Installation of #{formula_name} from a GitHub commit URL is unsupported! " \
"`brew extract #{formula_name}` to a stable tap on GitHub instead."
elsif url.match?(%r{^(https?|ftp)://})
raise UsageError, "Non-checksummed download of #{name} formula file from an arbitrary URL is unsupported! ",
"`brew extract` or `brew create` and `brew tap-new` to create a "\
"formula file in a tap on GitHub instead."
raise UnsupportedInstallationMethod,
"Non-checksummed download of #{name} formula file from an arbitrary URL is unsupported! " \
"`brew extract` or `brew create` and `brew tap-new` to create a formula file in a tap " \
"on GitHub instead."
end
HOMEBREW_CACHE_FORMULA.mkpath
FileUtils.rm_f(path)