| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # 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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-03 19:17:12 -04: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 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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}")} | 
					
						
							| 
									
										
										
										
											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-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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							| 
									
										
										
										
											2018-08-31 13:16:11 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   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}." | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   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
										 |  |  | 
 | 
					
						
							|  |  |  |   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 |