Use odie instead of bare exception

The reason that odie works well here
is that it doesn't print a stacktrace
or get caught and print the help page.
This commit is contained in:
apainintheneck 2023-01-02 10:59:08 -08:00
parent d291117468
commit d8c2e311ab
2 changed files with 12 additions and 6 deletions

View File

@ -15,9 +15,9 @@ module Homebrew
return unless @args.respond_to?(:cask?)
return unless @args.cask?
# NOTE: We don't raise a UsageError here because
# we don't want to print the help page.
raise "Invalid usage: Casks are not supported on Linux"
# NOTE: We don't raise an error here because we don't want
# to print the help page or a stack trace.
odie "Invalid `--cask` usage: Casks do not work on Linux"
end
end
end

View File

@ -573,7 +573,9 @@ describe Homebrew::CLI::Parser do
it "throws an error when defined" do
expect { parser.parse(["--cask"]) }
.to raise_error RuntimeError, "Invalid usage: Casks are not supported on Linux"
.to output("Error: Invalid `--cask` usage: Casks do not work on Linux\n").to_stderr
.and not_to_output.to_stdout
.and raise_exception SystemExit
end
end
@ -588,12 +590,16 @@ describe Homebrew::CLI::Parser do
it "throws an error when --cask defined" do
expect { parser.parse(["--cask"]) }
.to raise_error RuntimeError, "Invalid usage: Casks are not supported on Linux"
.to output("Error: Invalid `--cask` usage: Casks do not work on Linux\n").to_stderr
.and not_to_output.to_stdout
.and raise_exception SystemExit
end
it "throws an error when both defined" do
expect { parser.parse(["--cask", "--formula"]) }
.to raise_error RuntimeError, "Invalid usage: Casks are not supported on Linux"
.to output("Error: Invalid `--cask` usage: Casks do not work on Linux\n").to_stderr
.and not_to_output.to_stdout
.and raise_exception SystemExit
end
end
end