2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-09-06 08:29:14 +02:00
|
|
|
module Cask
|
2020-08-24 23:31:55 +02:00
|
|
|
# General cask error.
|
|
|
|
#
|
|
|
|
# @api private
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskError < RuntimeError; end
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Cask error containing multiple other errors.
|
|
|
|
#
|
|
|
|
# @api private
|
2019-04-03 19:17:12 -04:00
|
|
|
class MultipleCaskErrors < CaskError
|
|
|
|
def initialize(errors)
|
2020-08-21 13:09:51 +01:00
|
|
|
super()
|
2020-08-19 17:12:32 +01:00
|
|
|
|
2019-04-03 19:17:12 -04:00
|
|
|
@errors = errors
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
<<~EOS
|
|
|
|
Problems with multiple casks:
|
|
|
|
#{@errors.map(&:to_s).join("\n")}
|
|
|
|
EOS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Abstract cask error containing a cask token.
|
|
|
|
#
|
|
|
|
# @api private
|
2016-09-24 13:52:43 +02:00
|
|
|
class AbstractCaskErrorWithToken < CaskError
|
2020-07-07 11:29:33 +01:00
|
|
|
attr_reader :token, :reason
|
2016-08-18 22:11:42 +03:00
|
|
|
|
2017-06-11 02:00:59 +02:00
|
|
|
def initialize(token, reason = nil)
|
2020-08-19 17:12:32 +01:00
|
|
|
super()
|
|
|
|
|
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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask is not installed.
|
|
|
|
#
|
|
|
|
# @api private
|
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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask conflicts with another cask.
|
|
|
|
#
|
|
|
|
# @api private
|
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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask is not available.
|
|
|
|
#
|
|
|
|
# @api private
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskUnavailableError < AbstractCaskErrorWithToken
|
|
|
|
def to_s
|
2018-08-31 13:16:11 +00: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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask is unreadable.
|
|
|
|
#
|
|
|
|
# @api private
|
2018-07-29 11:05:23 +02:00
|
|
|
class CaskUnreadableError < CaskUnavailableError
|
|
|
|
def to_s
|
2018-08-31 13:16:11 +00:00
|
|
|
"Cask '#{token}' is unreadable#{reason.empty? ? "." : ": #{reason}"}"
|
2018-07-29 11:05:23 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask already exists.
|
|
|
|
#
|
|
|
|
# @api private
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskAlreadyCreatedError < AbstractCaskErrorWithToken
|
|
|
|
def to_s
|
2018-04-30 05:29:28 +08:00
|
|
|
%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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask is already installed.
|
|
|
|
#
|
|
|
|
# @api private
|
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:
|
2020-09-04 11:37:37 +02:00
|
|
|
#{Formatter.identifier("brew reinstall #{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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask depends on X11.
|
|
|
|
#
|
|
|
|
# @api private
|
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:
|
2016-10-26 21:45:15 -04:00
|
|
|
#{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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when there is a cyclic cask dependency.
|
|
|
|
#
|
|
|
|
# @api private
|
2017-06-28 17:53:59 +02:00
|
|
|
class CaskCyclicDependencyError < AbstractCaskErrorWithToken
|
2016-09-24 13:52:43 +02:00
|
|
|
def to_s
|
2018-08-31 13:16:11 +00:00
|
|
|
"Cask '#{token}' includes cyclic dependencies on other Casks#{reason.empty? ? "." : ": #{reason}"}"
|
2017-06-28 17:53:59 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask depends on itself.
|
|
|
|
#
|
|
|
|
# @api private
|
2017-06-28 17:53:59 +02:00
|
|
|
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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when no cask is specified.
|
|
|
|
#
|
|
|
|
# @api private
|
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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask is invalid.
|
|
|
|
#
|
|
|
|
# @api private
|
2016-09-24 13:52:43 +02:00
|
|
|
class CaskInvalidError < AbstractCaskErrorWithToken
|
|
|
|
def to_s
|
2018-08-31 13:16:11 +00: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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask token does not match the file name.
|
|
|
|
#
|
|
|
|
# @api private
|
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
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error with a cask's checksum.
|
|
|
|
#
|
|
|
|
# @api private
|
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
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask's checksum is missing.
|
|
|
|
#
|
|
|
|
# @api private
|
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:
|
2020-08-10 22:10:49 -06:00
|
|
|
#{Formatter.identifier('sha256 "#{actual}"')}
|
2016-09-24 13:52:43 +02:00
|
|
|
EOS
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask's checksum does not match.
|
|
|
|
#
|
|
|
|
# @api private
|
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:
|
2020-06-25 11:20:57 +01:00
|
|
|
#{Formatter.url("https://github.com/Homebrew/homebrew-cask/blob/HEAD/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
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error when a cask has no checksum and the `--require-sha` flag is passed.
|
|
|
|
#
|
|
|
|
# @api private
|
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
|
2018-08-31 13:16:11 +00:00
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error during quarantining of a file.
|
|
|
|
#
|
|
|
|
# @api private
|
2018-08-31 13:16:11 +00:00
|
|
|
class CaskQuarantineError < CaskError
|
|
|
|
attr_reader :path, :reason
|
|
|
|
|
|
|
|
def initialize(path, reason)
|
2020-08-21 13:09:51 +01:00
|
|
|
super()
|
2020-08-19 17:12:32 +01:00
|
|
|
|
2018-08-31 13:16:11 +00:00
|
|
|
@path = path
|
|
|
|
@reason = reason
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2019-04-28 15:16:47 +02:00
|
|
|
s = +"Failed to quarantine #{path}."
|
2018-08-31 13:16:11 +00:00
|
|
|
|
|
|
|
unless reason.empty?
|
|
|
|
s << " Here's the reason:\n"
|
|
|
|
s << Formatter.error(reason)
|
|
|
|
s << "\n" unless reason.end_with?("\n")
|
|
|
|
end
|
|
|
|
|
2019-04-29 13:02:15 +01:00
|
|
|
s.freeze
|
2018-08-31 13:16:11 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error while propagating quarantine information to subdirectories.
|
|
|
|
#
|
|
|
|
# @api private
|
2018-08-31 13:16:11 +00:00
|
|
|
class CaskQuarantinePropagationError < CaskQuarantineError
|
|
|
|
def to_s
|
2019-04-28 15:16:47 +02:00
|
|
|
s = +"Failed to quarantine one or more files within #{path}."
|
2018-08-31 13:16:11 +00:00
|
|
|
|
|
|
|
unless reason.empty?
|
|
|
|
s << " Here's the reason:\n"
|
|
|
|
s << Formatter.error(reason)
|
|
|
|
s << "\n" unless reason.end_with?("\n")
|
|
|
|
end
|
|
|
|
|
2019-04-29 13:02:15 +01:00
|
|
|
s.freeze
|
2018-08-31 13:16:11 +00:00
|
|
|
end
|
|
|
|
end
|
2018-09-07 15:37:31 +00:00
|
|
|
|
2020-08-24 23:31:55 +02:00
|
|
|
# Error while removing quarantine information.
|
|
|
|
#
|
|
|
|
# @api private
|
2018-09-07 15:37:31 +00:00
|
|
|
class CaskQuarantineReleaseError < CaskQuarantineError
|
|
|
|
def to_s
|
2019-04-28 15:16:47 +02:00
|
|
|
s = +"Failed to release #{path} from quarantine."
|
2018-09-07 15:37:31 +00:00
|
|
|
|
|
|
|
unless reason.empty?
|
|
|
|
s << " Here's the reason:\n"
|
|
|
|
s << Formatter.error(reason)
|
|
|
|
s << "\n" unless reason.end_with?("\n")
|
|
|
|
end
|
|
|
|
|
2019-04-29 13:02:15 +01:00
|
|
|
s.freeze
|
2018-09-07 15:37:31 +00:00
|
|
|
end
|
|
|
|
end
|
2016-08-18 22:11:42 +03:00
|
|
|
end
|