From 2e982cd2a28ffbbde40305e98e8d142c2874c8cf Mon Sep 17 00:00:00 2001
From: EricFromCanada <enk3@outlook.com>
Date: Thu, 3 Dec 2020 00:02:22 -0500
Subject: [PATCH] use odie when commands encounter errors

---
 Library/Homebrew/cmd/gist-logs.rb       | 2 +-
 Library/Homebrew/cmd/install.rb         | 4 ++--
 Library/Homebrew/cmd/migrate.rb         | 3 ++-
 Library/Homebrew/cmd/search.rb          | 2 +-
 Library/Homebrew/dev-cmd/create.rb      | 4 ++--
 Library/Homebrew/dev-cmd/edit.rb        | 2 +-
 Library/Homebrew/dev-cmd/pr-pull.rb     | 2 +-
 Library/Homebrew/dev-cmd/tap-new.rb     | 4 ++--
 Library/Homebrew/dev-cmd/unpack.rb      | 4 ++--
 Library/Homebrew/dev-cmd/update-test.rb | 2 +-
 10 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb
index 8f9a77891e..86436de503 100644
--- a/Library/Homebrew/cmd/gist-logs.rb
+++ b/Library/Homebrew/cmd/gist-logs.rb
@@ -103,7 +103,7 @@ module Homebrew
         logs[file.basename.to_s] = { content: contents }
       end
     end
-    raise "No logs." if logs.empty?
+    odie "No logs." if logs.empty?
 
     logs
   end
diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb
index 14455e8bd1..08e7e09675 100644
--- a/Library/Homebrew/cmd/install.rb
+++ b/Library/Homebrew/cmd/install.rb
@@ -183,14 +183,14 @@ module Homebrew
     formulae.each do |f|
       # head-only without --HEAD is an error
       if !args.HEAD? && f.stable.nil?
-        raise <<~EOS
+        odie <<~EOS
           #{f.full_name} is a head-only formula
           Install with `brew install --HEAD #{f.full_name}`
         EOS
       end
 
       # --HEAD, fail with no head defined
-      raise "No head is defined for #{f.full_name}" if args.HEAD? && f.head.nil?
+      odie "No head is defined for #{f.full_name}" if args.HEAD? && f.head.nil?
 
       installed_head_version = f.latest_head_version
       if installed_head_version &&
diff --git a/Library/Homebrew/cmd/migrate.rb b/Library/Homebrew/cmd/migrate.rb
index 34d61ea942..b33c204f63 100644
--- a/Library/Homebrew/cmd/migrate.rb
+++ b/Library/Homebrew/cmd/migrate.rb
@@ -31,7 +31,8 @@ module Homebrew
       if f.oldname
         rack = HOMEBREW_CELLAR/f.oldname
         raise NoSuchKegError, f.oldname if !rack.exist? || rack.subdirs.empty?
-        raise "#{rack} is a symlink" if rack.symlink?
+
+        odie "#{rack} is a symlink" if rack.symlink?
       end
 
       migrator = Migrator.new(f, force: args.force?)
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index 9d13a85c37..c21c5255e9 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -136,7 +136,7 @@ module Homebrew
         puts reason
       end
 
-      raise "No formulae or casks found for #{query.inspect}." if count.zero?
+      odie "No formulae or casks found for #{query.inspect}." if count.zero?
     end
 
     return unless $stdout.tty?
diff --git a/Library/Homebrew/dev-cmd/create.rb b/Library/Homebrew/dev-cmd/create.rb
index 1fa947fdce..bf6e540e0c 100644
--- a/Library/Homebrew/dev-cmd/create.rb
+++ b/Library/Homebrew/dev-cmd/create.rb
@@ -180,7 +180,7 @@ module Homebrew
     # unless --force is specified.
     unless args.force?
       if reason = MissingFormula.disallowed_reason(fc.name)
-        raise <<~EOS
+        odie <<~EOS
           The formula '#{fc.name}' is not allowed to be created.
           #{reason}
           If you really want to create this formula use `--force`.
@@ -189,7 +189,7 @@ module Homebrew
 
       if Formula.aliases.include? fc.name
         realname = Formulary.canonical_name(fc.name)
-        raise <<~EOS
+        odie <<~EOS
           The formula '#{realname}' is already aliased to '#{fc.name}'.
           Please check that you are not creating a duplicate.
           To force creation use `--force`.
diff --git a/Library/Homebrew/dev-cmd/edit.rb b/Library/Homebrew/dev-cmd/edit.rb
index 54ab8e650c..60aaacdd62 100644
--- a/Library/Homebrew/dev-cmd/edit.rb
+++ b/Library/Homebrew/dev-cmd/edit.rb
@@ -32,7 +32,7 @@ module Homebrew
     args = edit_args.parse
 
     unless (HOMEBREW_REPOSITORY/".git").directory?
-      raise <<~EOS
+      odie <<~EOS
         Changes will be lost!
         The first time you `brew update`, all local changes will be lost; you should
         thus `brew update` before you `brew edit`!
diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb
index d71d65aca2..fbf1a3c266 100644
--- a/Library/Homebrew/dev-cmd/pr-pull.rb
+++ b/Library/Homebrew/dev-cmd/pr-pull.rb
@@ -340,7 +340,7 @@ module Homebrew
   end
 
   def download_artifact(url, dir, pr)
-    raise "Credentials must be set to access the Artifacts API" if GitHub.api_credentials_type == :none
+    odie "Credentials must be set to access the Artifacts API" if GitHub.api_credentials_type == :none
 
     token = GitHub.api_credentials
     curl_args = ["--header", "Authorization: token #{token}"]
diff --git a/Library/Homebrew/dev-cmd/tap-new.rb b/Library/Homebrew/dev-cmd/tap-new.rb
index 6d01a3ee9a..e2043eeb73 100644
--- a/Library/Homebrew/dev-cmd/tap-new.rb
+++ b/Library/Homebrew/dev-cmd/tap-new.rb
@@ -37,7 +37,7 @@ module Homebrew
     branch = args.branch || "main"
 
     tap = args.named.to_taps.first
-    raise "Invalid tap name '#{tap_name}'" unless tap.path.to_s.match?(HOMEBREW_TAP_PATH_REGEX)
+    odie "Invalid tap name '#{tap_name}'" unless tap.path.to_s.match?(HOMEBREW_TAP_PATH_REGEX)
 
     titleized_user = tap.user.dup
     titleized_repo = tap.repo.dup
@@ -169,7 +169,7 @@ module Homebrew
   def write_path(tap, filename, content)
     path = tap.path/filename
     tap.path.mkpath
-    raise "#{path} already exists" if path.exist?
+    odie "#{path} already exists" if path.exist?
 
     path.write content
   end
diff --git a/Library/Homebrew/dev-cmd/unpack.rb b/Library/Homebrew/dev-cmd/unpack.rb
index 14f9a2e0af..feecfc80d2 100644
--- a/Library/Homebrew/dev-cmd/unpack.rb
+++ b/Library/Homebrew/dev-cmd/unpack.rb
@@ -45,13 +45,13 @@ module Homebrew
       unpack_dir = Pathname.pwd
     end
 
-    raise "Cannot write to #{unpack_dir}" unless unpack_dir.writable_real?
+    odie "Cannot write to #{unpack_dir}" unless unpack_dir.writable_real?
 
     formulae.each do |f|
       stage_dir = unpack_dir/"#{f.name}-#{f.version}"
 
       if stage_dir.exist?
-        raise "Destination #{stage_dir} already exists!" unless args.force?
+        odie "Destination #{stage_dir} already exists!" unless args.force?
 
         rm_rf stage_dir
       end
diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb
index 3de5641385..3d8063a569 100644
--- a/Library/Homebrew/dev-cmd/update-test.rb
+++ b/Library/Homebrew/dev-cmd/update-test.rb
@@ -134,7 +134,7 @@ module Homebrew
         start_log = Utils.popen_read("git", "log", "-1", "--decorate", "--oneline", start_commit).chomp
         end_log = Utils.popen_read("git", "log", "-1", "--decorate", "--oneline", end_commit).chomp
         actual_log = Utils.popen_read("git", "log", "-1", "--decorate", "--oneline", actual_end_commit).chomp
-        raise <<~EOS
+        odie <<~EOS
           brew update didn't update #{branch}!
           Start commit:        #{start_log}
           Expected end commit: #{end_log}
-- 
GitLab