brew/Library/Homebrew/cask/exceptions.rb

217 lines
5.2 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
2018-09-06 08:29:14 +02:00
module Cask
2016-09-24 13:52:43 +02:00
class CaskError < RuntimeError; end
2016-08-18 22:11:42 +03:00
class MultipleCaskErrors < CaskError
def initialize(errors)
@errors = errors
end
def to_s
<<~EOS
Problems with multiple casks:
#{@errors.map(&:to_s).join("\n")}
EOS
end
end
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
"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
class CaskUnreadableError < CaskUnavailableError
def to_s
"Cask '#{token}' is unreadable#{reason.empty? ? "." : ": #{reason}"}"
end
end
2016-09-24 13:52:43 +02:00
class CaskAlreadyCreatedError < AbstractCaskErrorWithToken
def to_s
%Q(Cask '#{token}' already exists. Run #{Formatter.identifier("brew cask edit #{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
2017-10-15 02:28:32 +02:00
<<~EOS
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 CaskX11DependencyError < AbstractCaskErrorWithToken
def to_s
2017-10-15 02:28:32 +02:00
<<~EOS
2019-04-08 12:47:15 -04:00
Cask '#{token}' requires XQuartz/X11, which can be installed using Homebrew Cask by running:
2017-06-11 02:00:59 +02:00
#{Formatter.identifier("brew cask install xquartz")}
2016-08-18 22:11:42 +03:00
2019-04-08 12:47:15 -04: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
"Cask '#{token}' includes cyclic dependencies on other Casks#{reason.empty? ? "." : ": #{reason}"}"
2017-06-28 17:53:59 +02:00
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
"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
2017-10-15 02:28:32 +02:00
<<~EOS
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
2017-10-15 02:28:32 +02:00
<<~EOS
2017-06-11 02:00:59 +02:00
Checksum for Cask '#{token}' does not match.
Expected: #{Formatter.success(expected.to_s)}
2019-04-01 16:02:13 -04:00
Actual: #{Formatter.error(actual.to_s)}
File: #{path}
2019-04-13 21:28:56 -04:00
To retry an incomplete download, remove the file above.
If the issue persists, visit:
2019-04-05 12:24:10 -04:00
#{Formatter.url("https://github.com/Homebrew/homebrew-cask/blob/master/doc/reporting_bugs/checksum_does_not_match_error.md")}
2017-06-11 02:00:59 +02:00
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
2017-10-15 02:28:32 +02:00
<<~EOS
2016-09-24 13:52:43 +02:00
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
class CaskQuarantineError < CaskError
attr_reader :path, :reason
def initialize(path, reason)
@path = path
@reason = reason
end
def to_s
2019-04-28 15:16:47 +02:00
s = +"Failed to quarantine #{path}."
unless reason.empty?
s << " Here's the reason:\n"
s << Formatter.error(reason)
s << "\n" unless reason.end_with?("\n")
end
s
end
end
class CaskQuarantinePropagationError < CaskQuarantineError
def to_s
2019-04-28 15:16:47 +02:00
s = +"Failed to quarantine one or more files within #{path}."
unless reason.empty?
s << " Here's the reason:\n"
s << Formatter.error(reason)
s << "\n" unless reason.end_with?("\n")
end
s
end
end
class CaskQuarantineReleaseError < CaskQuarantineError
def to_s
2019-04-28 15:16:47 +02:00
s = +"Failed to release #{path} from quarantine."
unless reason.empty?
s << " Here's the reason:\n"
s << Formatter.error(reason)
s << "\n" unless reason.end_with?("\n")
end
s
end
end
2016-08-18 22:11:42 +03:00
end