From 7fb74cb1dc9ed34138d62758e4b543d3142c661a Mon Sep 17 00:00:00 2001 From: Alexander Bayandin Date: Thu, 2 Dec 2021 15:53:09 +0000 Subject: [PATCH] Fix error message duplication for installation from URL --- Library/Homebrew/exceptions.rb | 2 ++ Library/Homebrew/formulary.rb | 12 +++++++----- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 58aa822dc0..0a5526a5f4 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -45,6 +45,8 @@ class KegUnspecifiedError < UsageError end end +class UnsupportedInstallationMethod < RuntimeError; end + class MultipleVersionsInstalledError < RuntimeError; end class NotAKegError < RuntimeError; end diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 58c55e18a1..4889b5785e 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -274,12 +274,14 @@ module Formulary def load_file(flags:, ignore_errors:) if %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(?:/Formula)?/(?[\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)