brew/Library/Homebrew/cask/lib/hbc/exceptions.rb

172 lines
4.4 KiB
Ruby
Raw Normal View History

2016-09-24 13:52:43 +02:00
module Hbc
class CaskError < RuntimeError; end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
class AbstractCaskErrorWithToken < CaskError
attr_reader :token
2017-06-11 02:00:59 +02:00
attr_reader :reason
2016-08-18 22:11:42 +03:00
2017-06-11 02:00:59 +02:00
def initialize(token, reason = nil)
2016-09-24 13:52:43 +02:00
@token = token
2017-06-11 02:00:59 +02:00
@reason = reason.to_s
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
class CaskNotInstalledError < AbstractCaskErrorWithToken
def to_s
2017-06-11 02:00:59 +02:00
"Cask '#{token}' is not installed."
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2017-08-05 15:56:34 +02:00
class CaskConflictError < AbstractCaskErrorWithToken
attr_reader :conflicting_cask
def initialize(token, conflicting_cask)
super(token)
@conflicting_cask = conflicting_cask
end
def to_s
"Cask '#{token}' conflicts with '#{conflicting_cask}'."
end
end
2016-09-24 13:52:43 +02:00
class CaskUnavailableError < AbstractCaskErrorWithToken
def to_s
2017-06-11 02:00:59 +02:00
"Cask '#{token}' is unavailable" << (reason.empty? ? "." : ": #{reason}")
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
class CaskAlreadyCreatedError < AbstractCaskErrorWithToken
def to_s
2017-06-11 02:00:59 +02:00
%Q(Cask '#{token}' already exists. Run #{Formatter.identifier("brew cask cat #{token}")} to edit it.)
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
class CaskAlreadyInstalledError < AbstractCaskErrorWithToken
def to_s
<<-EOS.undent
2017-06-11 02:00:59 +02:00
Cask '#{token}' is already installed.
2016-08-18 22:11:42 +03:00
2017-06-11 02:00:59 +02:00
To re-install #{token}, run:
#{Formatter.identifier("brew cask reinstall #{token}")}
EOS
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
class CaskCommandFailedError < CaskError
def initialize(cmd, stdout, stderr, status)
@cmd = cmd
@stdout = stdout
@stderr = stderr
@status = status
end
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
def to_s
s = "Command failed to execute!\n"
s.concat("\n")
s.concat("==> Failed command:\n")
2016-10-11 17:35:09 +02:00
s.concat(@cmd.join(" ")).concat("\n")
s.concat("\n")
s.concat("==> Standard Output of failed command:\n")
s.concat(@stdout).concat("\n")
s.concat("\n")
s.concat("==> Standard Error of failed command:\n")
s.concat(@stderr).concat("\n")
s.concat("\n")
s.concat("==> Exit status of failed command:\n")
s.concat(@status.inspect).concat("\n")
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
class CaskX11DependencyError < AbstractCaskErrorWithToken
def to_s
<<-EOS.undent
2017-06-11 02:00:59 +02:00
Cask '#{token}' requires XQuartz/X11, which can be installed using Homebrew-Cask by running
#{Formatter.identifier("brew cask install xquartz")}
2016-08-18 22:11:42 +03:00
2016-09-24 13:52:43 +02:00
or manually, by downloading the package from
#{Formatter.url("https://www.xquartz.org/")}
2016-09-24 13:52:43 +02:00
EOS
end
2016-08-18 22:11:42 +03:00
end
2017-06-28 17:53:59 +02:00
class CaskCyclicDependencyError < AbstractCaskErrorWithToken
2016-09-24 13:52:43 +02:00
def to_s
2017-06-28 17:53:59 +02:00
"Cask '#{token}' includes cyclic dependencies on other Casks" << (reason.empty? ? "." : ": #{reason}")
end
end
class CaskSelfReferencingDependencyError < CaskCyclicDependencyError
def to_s
"Cask '#{token}' depends on itself."
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
class CaskUnspecifiedError < CaskError
def to_s
2017-06-11 02:00:59 +02:00
"This command requires a Cask token."
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2016-09-24 13:52:43 +02:00
class CaskInvalidError < AbstractCaskErrorWithToken
def to_s
2017-06-28 17:53:59 +02:00
"Cask '#{token}' definition is invalid" << (reason.empty? ? "." : ": #{reason}")
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2017-06-11 02:00:59 +02:00
class CaskTokenMismatchError < CaskInvalidError
2016-09-24 13:52:43 +02:00
def initialize(token, header_token)
2017-06-11 02:00:59 +02:00
super(token, "Token '#{header_token}' in header line does not match the file name.")
2016-09-24 13:52:43 +02:00
end
2016-08-18 22:11:42 +03:00
end
2017-06-11 02:00:59 +02:00
class CaskSha256Error < AbstractCaskErrorWithToken
attr_reader :expected, :actual
2016-08-18 22:11:42 +03:00
2017-06-11 02:00:59 +02:00
def initialize(token, expected = nil, actual = nil)
super(token)
2016-09-24 13:52:43 +02:00
@expected = expected
@actual = actual
end
2017-06-11 02:00:59 +02:00
end
2016-08-18 22:11:42 +03:00
2017-06-11 02:00:59 +02:00
class CaskSha256MissingError < CaskSha256Error
2016-09-24 13:52:43 +02:00
def to_s
<<-EOS.undent
2017-06-11 02:00:59 +02:00
Cask '#{token}' requires a checksum:
#{Formatter.identifier("sha256 '#{actual}'")}
2016-09-24 13:52:43 +02:00
EOS
end
2016-08-18 22:11:42 +03:00
end
2017-06-11 02:00:59 +02:00
class CaskSha256MismatchError < CaskSha256Error
attr_reader :path
def initialize(token, expected, actual, path)
super(token, expected, actual)
@path = path
end
def to_s
<<-EOS.undent
Checksum for Cask '#{token}' does not match.
Expected: #{Formatter.success(expected.to_s)}
Actual: #{Formatter.error(actual.to_s)}
File: #{path}
To retry an incomplete download, remove the file above.
EOS
2016-09-24 13:52:43 +02:00
end
2017-06-11 02:00:59 +02:00
end
2016-09-24 13:52:43 +02:00
2017-06-11 02:00:59 +02:00
class CaskNoShasumError < CaskSha256Error
2016-09-24 13:52:43 +02:00
def to_s
<<-EOS.undent
Cask '#{token}' does not have a sha256 checksum defined and was not installed.
2017-06-11 02:00:59 +02:00
This means you have the #{Formatter.identifier("--require-sha")} option set, perhaps in your HOMEBREW_CASK_OPTS.
2016-09-24 13:52:43 +02:00
EOS
end
2016-08-18 22:11:42 +03:00
end
end