Document exceptions.
This commit is contained in:
parent
f98223ba1a
commit
0240128f29
@ -3,6 +3,7 @@
|
|||||||
require "shellwords"
|
require "shellwords"
|
||||||
require "utils"
|
require "utils"
|
||||||
|
|
||||||
|
# Raised when a command is used wrong.
|
||||||
class UsageError < RuntimeError
|
class UsageError < RuntimeError
|
||||||
attr_reader :reason
|
attr_reader :reason
|
||||||
|
|
||||||
@ -19,12 +20,14 @@ class UsageError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a command expects a formula and none was specified.
|
||||||
class FormulaUnspecifiedError < UsageError
|
class FormulaUnspecifiedError < UsageError
|
||||||
def initialize
|
def initialize
|
||||||
super "this command requires a formula argument"
|
super "this command requires a formula argument"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a command expects a keg and none was specified.
|
||||||
class KegUnspecifiedError < UsageError
|
class KegUnspecifiedError < UsageError
|
||||||
def initialize
|
def initialize
|
||||||
super "this command requires a keg argument"
|
super "this command requires a keg argument"
|
||||||
@ -35,6 +38,7 @@ class MultipleVersionsInstalledError < RuntimeError; end
|
|||||||
|
|
||||||
class NotAKegError < RuntimeError; end
|
class NotAKegError < RuntimeError; end
|
||||||
|
|
||||||
|
# Raised when a keg doesn't exist.
|
||||||
class NoSuchKegError < RuntimeError
|
class NoSuchKegError < RuntimeError
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
@ -44,6 +48,7 @@ class NoSuchKegError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when an invalid attribute is used in a formula.
|
||||||
class FormulaValidationError < StandardError
|
class FormulaValidationError < StandardError
|
||||||
attr_reader :attr, :formula
|
attr_reader :attr, :formula
|
||||||
|
|
||||||
@ -56,10 +61,14 @@ end
|
|||||||
|
|
||||||
class FormulaSpecificationError < StandardError; end
|
class FormulaSpecificationError < StandardError; end
|
||||||
|
|
||||||
|
# Raised when a deprecated method is used.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
class MethodDeprecatedError < StandardError
|
class MethodDeprecatedError < StandardError
|
||||||
attr_accessor :issues_url
|
attr_accessor :issues_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula is not available.
|
||||||
class FormulaUnavailableError < RuntimeError
|
class FormulaUnavailableError < RuntimeError
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
attr_accessor :dependent
|
attr_accessor :dependent
|
||||||
@ -79,6 +88,9 @@ class FormulaUnavailableError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Shared methods for formula class errors.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
module FormulaClassUnavailableErrorModule
|
module FormulaClassUnavailableErrorModule
|
||||||
attr_reader :path, :class_name, :class_list
|
attr_reader :path, :class_name, :class_list
|
||||||
|
|
||||||
@ -107,6 +119,7 @@ module FormulaClassUnavailableErrorModule
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula does not contain a formula class.
|
||||||
class FormulaClassUnavailableError < FormulaUnavailableError
|
class FormulaClassUnavailableError < FormulaUnavailableError
|
||||||
include FormulaClassUnavailableErrorModule
|
include FormulaClassUnavailableErrorModule
|
||||||
|
|
||||||
@ -118,6 +131,9 @@ class FormulaClassUnavailableError < FormulaUnavailableError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Shared methods for formula unreadable errors.
|
||||||
|
#
|
||||||
|
# @api private
|
||||||
module FormulaUnreadableErrorModule
|
module FormulaUnreadableErrorModule
|
||||||
attr_reader :formula_error
|
attr_reader :formula_error
|
||||||
|
|
||||||
@ -126,6 +142,7 @@ module FormulaUnreadableErrorModule
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula is unreadable.
|
||||||
class FormulaUnreadableError < FormulaUnavailableError
|
class FormulaUnreadableError < FormulaUnavailableError
|
||||||
include FormulaUnreadableErrorModule
|
include FormulaUnreadableErrorModule
|
||||||
|
|
||||||
@ -135,6 +152,7 @@ class FormulaUnreadableError < FormulaUnavailableError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula in a specific tap is unavailable.
|
||||||
class TapFormulaUnavailableError < FormulaUnavailableError
|
class TapFormulaUnavailableError < FormulaUnavailableError
|
||||||
attr_reader :tap, :user, :repo
|
attr_reader :tap, :user, :repo
|
||||||
|
|
||||||
@ -152,6 +170,7 @@ class TapFormulaUnavailableError < FormulaUnavailableError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula in a specific tap does not contain a formula class.
|
||||||
class TapFormulaClassUnavailableError < TapFormulaUnavailableError
|
class TapFormulaClassUnavailableError < TapFormulaUnavailableError
|
||||||
include FormulaClassUnavailableErrorModule
|
include FormulaClassUnavailableErrorModule
|
||||||
|
|
||||||
@ -165,6 +184,7 @@ class TapFormulaClassUnavailableError < TapFormulaUnavailableError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula in a specific tap is unreadable.
|
||||||
class TapFormulaUnreadableError < TapFormulaUnavailableError
|
class TapFormulaUnreadableError < TapFormulaUnavailableError
|
||||||
include FormulaUnreadableErrorModule
|
include FormulaUnreadableErrorModule
|
||||||
|
|
||||||
@ -174,6 +194,7 @@ class TapFormulaUnreadableError < TapFormulaUnavailableError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula with the same name is found multiple taps.
|
||||||
class TapFormulaAmbiguityError < RuntimeError
|
class TapFormulaAmbiguityError < RuntimeError
|
||||||
attr_reader :name, :paths, :formulae
|
attr_reader :name, :paths, :formulae
|
||||||
|
|
||||||
@ -192,6 +213,7 @@ class TapFormulaAmbiguityError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula's old name in a specific tap is found in multiple taps.
|
||||||
class TapFormulaWithOldnameAmbiguityError < RuntimeError
|
class TapFormulaWithOldnameAmbiguityError < RuntimeError
|
||||||
attr_reader :name, :possible_tap_newname_formulae, :taps
|
attr_reader :name, :possible_tap_newname_formulae, :taps
|
||||||
|
|
||||||
@ -212,6 +234,7 @@ class TapFormulaWithOldnameAmbiguityError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a tap is unavailable.
|
||||||
class TapUnavailableError < RuntimeError
|
class TapUnavailableError < RuntimeError
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
@ -224,6 +247,7 @@ class TapUnavailableError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a tap's remote does not match the actual remote.
|
||||||
class TapRemoteMismatchError < RuntimeError
|
class TapRemoteMismatchError < RuntimeError
|
||||||
attr_reader :name, :expected_remote, :actual_remote
|
attr_reader :name, :expected_remote, :actual_remote
|
||||||
|
|
||||||
@ -239,6 +263,7 @@ class TapRemoteMismatchError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a tap is already installed.
|
||||||
class TapAlreadyTappedError < RuntimeError
|
class TapAlreadyTappedError < RuntimeError
|
||||||
attr_reader :name
|
attr_reader :name
|
||||||
|
|
||||||
@ -251,6 +276,7 @@ class TapAlreadyTappedError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when another Homebrew operation is already in progress.
|
||||||
class OperationInProgressError < RuntimeError
|
class OperationInProgressError < RuntimeError
|
||||||
def initialize(name)
|
def initialize(name)
|
||||||
message = <<~EOS
|
message = <<~EOS
|
||||||
@ -265,12 +291,14 @@ end
|
|||||||
|
|
||||||
class CannotInstallFormulaError < RuntimeError; end
|
class CannotInstallFormulaError < RuntimeError; end
|
||||||
|
|
||||||
|
# Raised when a formula installation was already attempted.
|
||||||
class FormulaInstallationAlreadyAttemptedError < RuntimeError
|
class FormulaInstallationAlreadyAttemptedError < RuntimeError
|
||||||
def initialize(formula)
|
def initialize(formula)
|
||||||
super "Formula installation already attempted: #{formula.full_name}"
|
super "Formula installation already attempted: #{formula.full_name}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when there are unsatisfied requirements.
|
||||||
class UnsatisfiedRequirements < RuntimeError
|
class UnsatisfiedRequirements < RuntimeError
|
||||||
def initialize(reqs)
|
def initialize(reqs)
|
||||||
if reqs.length == 1
|
if reqs.length == 1
|
||||||
@ -281,6 +309,7 @@ class UnsatisfiedRequirements < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a formula conflicts with another one.
|
||||||
class FormulaConflictError < RuntimeError
|
class FormulaConflictError < RuntimeError
|
||||||
attr_reader :formula, :conflicts
|
attr_reader :formula, :conflicts
|
||||||
|
|
||||||
@ -313,6 +342,7 @@ class FormulaConflictError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raise when the Python version cannot be detected automatically.
|
||||||
class FormulaUnknownPythonError < RuntimeError
|
class FormulaUnknownPythonError < RuntimeError
|
||||||
def initialize(formula)
|
def initialize(formula)
|
||||||
super <<~EOS
|
super <<~EOS
|
||||||
@ -325,6 +355,7 @@ class FormulaUnknownPythonError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raise when two Python versions are detected simultaneously.
|
||||||
class FormulaAmbiguousPythonError < RuntimeError
|
class FormulaAmbiguousPythonError < RuntimeError
|
||||||
def initialize(formula)
|
def initialize(formula)
|
||||||
super <<~EOS
|
super <<~EOS
|
||||||
@ -336,6 +367,7 @@ class FormulaAmbiguousPythonError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when an error occurs during a formula build.
|
||||||
class BuildError < RuntimeError
|
class BuildError < RuntimeError
|
||||||
attr_reader :cmd, :args, :env
|
attr_reader :cmd, :args, :env
|
||||||
attr_accessor :formula, :options
|
attr_accessor :formula, :options
|
||||||
@ -561,12 +593,14 @@ class ChecksumMismatchError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a resource is missing.
|
||||||
class ResourceMissingError < ArgumentError
|
class ResourceMissingError < ArgumentError
|
||||||
def initialize(formula, resource)
|
def initialize(formula, resource)
|
||||||
super "#{formula.full_name} does not define resource #{resource.inspect}"
|
super "#{formula.full_name} does not define resource #{resource.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a resource is specified multiple times.
|
||||||
class DuplicateResourceError < ArgumentError
|
class DuplicateResourceError < ArgumentError
|
||||||
def initialize(resource)
|
def initialize(resource)
|
||||||
super "Resource #{resource.inspect} is defined more than once"
|
super "Resource #{resource.inspect} is defined more than once"
|
||||||
@ -576,6 +610,7 @@ end
|
|||||||
# Raised when a single patch file is not found and apply hasn't been specified.
|
# Raised when a single patch file is not found and apply hasn't been specified.
|
||||||
class MissingApplyError < RuntimeError; end
|
class MissingApplyError < RuntimeError; end
|
||||||
|
|
||||||
|
# Raised when a bottle does not contain a formula file.
|
||||||
class BottleFormulaUnavailableError < RuntimeError
|
class BottleFormulaUnavailableError < RuntimeError
|
||||||
def initialize(bottle_path, formula_path)
|
def initialize(bottle_path, formula_path)
|
||||||
super <<~EOS
|
super <<~EOS
|
||||||
@ -604,6 +639,7 @@ class ChildProcessError < RuntimeError
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Raised when a macOS version is unsupported.
|
||||||
class MacOSVersionError < RuntimeError
|
class MacOSVersionError < RuntimeError
|
||||||
attr_reader :version
|
attr_reader :version
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user