Merge pull request #12507 from bayandin/fix-installing-from-url-exception

Fix error message duplication for installation from URL
This commit is contained in:
Alexander Bayandin 2021-12-07 13:29:23 +00:00 committed by GitHub
commit 998a4028cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)