Skip to content
Snippets Groups Projects
Commit d9363a15 authored by Martin Afanasjew's avatar Martin Afanasjew
Browse files

exceptions: add reason to 'UsageError' exception

Use the `reason` attribute to be able to handle `UsageError` subclasses
more uniformly and simplify logic in `brew.rb` to handle them together.
parent cf3486f9
No related branches found
No related tags found
No related merge requests found
class UsageError < RuntimeError; end
class FormulaUnspecifiedError < UsageError; end
class KegUnspecifiedError < UsageError; end
class UsageError < RuntimeError
attr_reader :reason
def initialize(reason = nil)
@reason = reason
end
def to_s
s = "Invalid usage"
s += ": #{reason}" if reason
s
end
end
class FormulaUnspecifiedError < UsageError
def initialize
super "This command requires a formula argument"
end
end
class KegUnspecifiedError < UsageError
def initialize
super "This command requires a keg argument"
end
end
class MultipleVersionsInstalledError < RuntimeError
attr_reader :name
......
......@@ -113,13 +113,9 @@ begin
end
end
rescue FormulaUnspecifiedError
abort "This command requires a formula argument"
rescue KegUnspecifiedError
abort "This command requires a keg argument"
rescue UsageError
rescue UsageError => e
require "cmd/help"
Homebrew.help cmd, :usage_error => "Invalid usage"
Homebrew.help cmd, :usage_error => e.message
rescue SystemExit => e
onoe "Kernel.exit" if ARGV.verbose? && !e.success?
$stderr.puts e.backtrace if ARGV.debug?
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment