aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/exceptions.rb
diff options
context:
space:
mode:
authorMartin Afanasjew2016-04-19 08:11:17 +0200
committerMartin Afanasjew2016-04-20 13:46:10 +0200
commitd9363a15590ddb8aad3e8e5444a972eaa79fd05e (patch)
tree5c3a8ee063a8c314b4e9c6989025e94295ec6cd7 /Library/Homebrew/exceptions.rb
parentcf3486f98a5ddc8eae3c511f759471eff79cfcf8 (diff)
downloadbrew-d9363a15590ddb8aad3e8e5444a972eaa79fd05e.tar.bz2
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.
Diffstat (limited to 'Library/Homebrew/exceptions.rb')
-rw-r--r--Library/Homebrew/exceptions.rb28
1 files changed, 25 insertions, 3 deletions
diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb
index 130d3f505..144f70768 100644
--- a/Library/Homebrew/exceptions.rb
+++ b/Library/Homebrew/exceptions.rb
@@ -1,6 +1,28 @@
-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