use odie when commands encounter errors

This commit is contained in:
EricFromCanada 2020-12-03 00:02:22 -05:00
parent a72ddfdc67
commit 2e982cd2a2
10 changed files with 15 additions and 14 deletions

View File

@ -103,7 +103,7 @@ module Homebrew
logs[file.basename.to_s] = { content: contents } logs[file.basename.to_s] = { content: contents }
end end
end end
raise "No logs." if logs.empty? odie "No logs." if logs.empty?
logs logs
end end

View File

@ -183,14 +183,14 @@ module Homebrew
formulae.each do |f| formulae.each do |f|
# head-only without --HEAD is an error # head-only without --HEAD is an error
if !args.HEAD? && f.stable.nil? if !args.HEAD? && f.stable.nil?
raise <<~EOS odie <<~EOS
#{f.full_name} is a head-only formula #{f.full_name} is a head-only formula
Install with `brew install --HEAD #{f.full_name}` Install with `brew install --HEAD #{f.full_name}`
EOS EOS
end end
# --HEAD, fail with no head defined # --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 installed_head_version = f.latest_head_version
if installed_head_version && if installed_head_version &&

View File

@ -31,7 +31,8 @@ module Homebrew
if f.oldname if f.oldname
rack = HOMEBREW_CELLAR/f.oldname rack = HOMEBREW_CELLAR/f.oldname
raise NoSuchKegError, f.oldname if !rack.exist? || rack.subdirs.empty? 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 end
migrator = Migrator.new(f, force: args.force?) migrator = Migrator.new(f, force: args.force?)

View File

@ -136,7 +136,7 @@ module Homebrew
puts reason puts reason
end 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 end
return unless $stdout.tty? return unless $stdout.tty?

View File

@ -180,7 +180,7 @@ module Homebrew
# unless --force is specified. # unless --force is specified.
unless args.force? unless args.force?
if reason = MissingFormula.disallowed_reason(fc.name) if reason = MissingFormula.disallowed_reason(fc.name)
raise <<~EOS odie <<~EOS
The formula '#{fc.name}' is not allowed to be created. The formula '#{fc.name}' is not allowed to be created.
#{reason} #{reason}
If you really want to create this formula use `--force`. If you really want to create this formula use `--force`.
@ -189,7 +189,7 @@ module Homebrew
if Formula.aliases.include? fc.name if Formula.aliases.include? fc.name
realname = Formulary.canonical_name(fc.name) realname = Formulary.canonical_name(fc.name)
raise <<~EOS odie <<~EOS
The formula '#{realname}' is already aliased to '#{fc.name}'. The formula '#{realname}' is already aliased to '#{fc.name}'.
Please check that you are not creating a duplicate. Please check that you are not creating a duplicate.
To force creation use `--force`. To force creation use `--force`.

View File

@ -32,7 +32,7 @@ module Homebrew
args = edit_args.parse args = edit_args.parse
unless (HOMEBREW_REPOSITORY/".git").directory? unless (HOMEBREW_REPOSITORY/".git").directory?
raise <<~EOS odie <<~EOS
Changes will be lost! Changes will be lost!
The first time you `brew update`, all local changes will be lost; you should The first time you `brew update`, all local changes will be lost; you should
thus `brew update` before you `brew edit`! thus `brew update` before you `brew edit`!

View File

@ -340,7 +340,7 @@ module Homebrew
end end
def download_artifact(url, dir, pr) 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 token = GitHub.api_credentials
curl_args = ["--header", "Authorization: token #{token}"] curl_args = ["--header", "Authorization: token #{token}"]

View File

@ -37,7 +37,7 @@ module Homebrew
branch = args.branch || "main" branch = args.branch || "main"
tap = args.named.to_taps.first 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_user = tap.user.dup
titleized_repo = tap.repo.dup titleized_repo = tap.repo.dup
@ -169,7 +169,7 @@ module Homebrew
def write_path(tap, filename, content) def write_path(tap, filename, content)
path = tap.path/filename path = tap.path/filename
tap.path.mkpath tap.path.mkpath
raise "#{path} already exists" if path.exist? odie "#{path} already exists" if path.exist?
path.write content path.write content
end end

View File

@ -45,13 +45,13 @@ module Homebrew
unpack_dir = Pathname.pwd unpack_dir = Pathname.pwd
end 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| formulae.each do |f|
stage_dir = unpack_dir/"#{f.name}-#{f.version}" stage_dir = unpack_dir/"#{f.name}-#{f.version}"
if stage_dir.exist? 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 rm_rf stage_dir
end end

View File

@ -134,7 +134,7 @@ module Homebrew
start_log = Utils.popen_read("git", "log", "-1", "--decorate", "--oneline", start_commit).chomp 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 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 actual_log = Utils.popen_read("git", "log", "-1", "--decorate", "--oneline", actual_end_commit).chomp
raise <<~EOS odie <<~EOS
brew update didn't update #{branch}! brew update didn't update #{branch}!
Start commit: #{start_log} Start commit: #{start_log}
Expected end commit: #{end_log} Expected end commit: #{end_log}