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
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def initialize(token)
|
|
|
|
@token = token
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskNotInstalledError < AbstractCaskErrorWithToken
|
|
|
|
def to_s
|
|
|
|
"#{token} is not installed"
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskUnavailableError < AbstractCaskErrorWithToken
|
|
|
|
def to_s
|
|
|
|
"No available Cask for #{token}"
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskAlreadyCreatedError < AbstractCaskErrorWithToken
|
|
|
|
def to_s
|
|
|
|
%Q{A Cask for #{token} already exists. Run "brew cask cat #{token}" to see it.}
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskAlreadyInstalledError < AbstractCaskErrorWithToken
|
|
|
|
def to_s
|
2016-10-01 23:18:13 +02:00
|
|
|
s = <<-EOS.undent
|
|
|
|
A Cask for #{token} is already installed.
|
|
|
|
EOS
|
|
|
|
|
|
|
|
s.concat("\n").concat(reinstall_message)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def reinstall_message
|
|
|
|
<<-EOS.undent
|
|
|
|
To re-install #{token}, run:
|
2016-10-02 19:53:34 +02:00
|
|
|
brew cask uninstall --force #{token} && brew cask install #{token}
|
2016-10-01 23:18:13 +02:00
|
|
|
EOS
|
2016-09-24 13:52:43 +02:00
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-10-01 23:18:13 +02:00
|
|
|
class CaskAlreadyInstalledAutoUpdatesError < CaskAlreadyInstalledError
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_s
|
2016-10-01 23:18:13 +02:00
|
|
|
s = <<-EOS.undent
|
|
|
|
A Cask for #{token} is already installed and using auto-updates.
|
|
|
|
EOS
|
|
|
|
|
|
|
|
s.concat("\n").concat(reinstall_message)
|
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
|
2016-10-01 23:18:38 +02:00
|
|
|
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")
|
2016-10-01 23:18:38 +02:00
|
|
|
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
|
|
|
|
#{token} requires XQuartz/X11, which can be installed via homebrew-cask by
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
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
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
https://www.xquartz.org/
|
|
|
|
EOS
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskCyclicCaskDependencyError < AbstractCaskErrorWithToken
|
|
|
|
def to_s
|
|
|
|
"Cask '#{token}' includes cyclic dependencies on other Casks and could not be installed."
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskUnspecifiedError < CaskError
|
|
|
|
def to_s
|
|
|
|
"This command requires a Cask token"
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskInvalidError < AbstractCaskErrorWithToken
|
|
|
|
attr_reader :submsg
|
|
|
|
def initialize(token, *submsg)
|
|
|
|
super(token)
|
|
|
|
@submsg = submsg.join(" ")
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_s
|
|
|
|
"Cask '#{token}' definition is invalid" + (!submsg.empty? ? ": #{submsg}" : "")
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskTokenDoesNotMatchError < CaskInvalidError
|
|
|
|
def initialize(token, header_token)
|
|
|
|
super(token, "Bad header line: '#{header_token}' does not match file name")
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskSha256MissingError < ArgumentError
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskSha256MismatchError < RuntimeError
|
|
|
|
attr_reader :path, :expected, :actual
|
|
|
|
def initialize(path, expected, actual)
|
|
|
|
@path = path
|
|
|
|
@expected = expected
|
|
|
|
@actual = actual
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_s
|
|
|
|
<<-EOS.undent
|
|
|
|
sha256 mismatch
|
|
|
|
Expected: #{expected}
|
|
|
|
Actual: #{actual}
|
|
|
|
File: #{path}
|
|
|
|
To retry an incomplete download, remove the file above.
|
|
|
|
EOS
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskNoShasumError < CaskError
|
|
|
|
attr_reader :token
|
|
|
|
def initialize(token)
|
|
|
|
@token = token
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
<<-EOS.undent
|
|
|
|
Cask '#{token}' does not have a sha256 checksum defined and was not installed.
|
|
|
|
This means you have the "--require-sha" option set, perhaps in your HOMEBREW_CASK_OPTS.
|
|
|
|
EOS
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
end
|