brew/Library/Homebrew/exceptions.rb

304 lines
7.5 KiB
Ruby
Raw Normal View History

2011-03-12 23:06:45 -08:00
class UsageError < RuntimeError; end
class FormulaUnspecifiedError < UsageError; end
class KegUnspecifiedError < UsageError; end
2011-03-12 23:06:45 -08:00
class MultipleVersionsInstalledError < RuntimeError
attr_reader :name
2010-11-12 20:59:53 -08:00
def initialize name
@name = name
super "#{name} has multiple installed versions"
end
end
class NotAKegError < RuntimeError; end
2011-03-12 23:06:45 -08:00
class NoSuchKegError < RuntimeError
attr_reader :name
2010-11-12 20:59:53 -08:00
def initialize name
@name = name
super "No such keg: #{HOMEBREW_CELLAR}/#{name}"
end
end
class FormulaValidationError < StandardError
attr_reader :attr
def initialize(attr, value)
@attr = attr
super "invalid attribute: #{attr} (#{value.inspect})"
end
end
2013-08-06 21:48:05 -07:00
class FormulaSpecificationError < StandardError; end
class FormulaUnavailableError < RuntimeError
attr_reader :name
attr_accessor :dependent
def initialize name
@name = name
end
def dependent_s
"(dependency of #{dependent})" if dependent and dependent != name
end
def to_s
"No available formula for #{name} #{dependent_s}"
end
end
class TapFormulaUnavailableError < FormulaUnavailableError
attr_reader :tap, :user, :repo
2010-11-12 20:59:53 -08:00
def initialize tap, name
@tap = tap
@user = tap.user
@repo = tap.repo
super "#{tap}/#{name}"
end
def to_s
s = super
s += "\nPlease tap it and then try again: brew tap #{tap}" unless tap.installed?
s
end
end
2015-05-08 19:16:06 +08:00
class TapFormulaAmbiguityError < RuntimeError
attr_reader :name, :paths, :formulae
def initialize name, paths
@name = name
@paths = paths
@formulae = paths.map do |path|
path.to_s =~ HOMEBREW_TAP_PATH_REGEX
"#{$1}/#{$2.sub("homebrew-", "")}/#{path.basename(".rb")}"
end
super <<-EOS.undent
Formulae found in multiple taps: #{formulae.map { |f| "\n * #{f}" }.join}
Please use the fully-qualified name e.g. #{formulae.first} to refer the formula.
EOS
end
end
2015-06-13 14:32:10 +08:00
class TapUnavailableError < RuntimeError
attr_reader :name
def initialize name
@name = name
super <<-EOS.undent
No available tap #{name}.
EOS
end
end
class OperationInProgressError < RuntimeError
def initialize name
message = <<-EOS.undent
Operation already in progress for #{name}
Another active Homebrew process is already using #{name}.
Please wait for it to finish or terminate it to continue.
EOS
super message
end
end
2013-08-06 21:48:05 -07:00
class CannotInstallFormulaError < RuntimeError; end
class FormulaInstallationAlreadyAttemptedError < RuntimeError
2014-09-12 21:28:25 -05:00
def initialize(formula)
2015-05-27 22:16:48 +08:00
super "Formula installation already attempted: #{formula.full_name}"
end
end
class UnsatisfiedRequirements < RuntimeError
def initialize(reqs)
if reqs.length == 1
super "An unsatisfied requirement failed this build."
else
super "Unsatisified requirements failed this build."
end
end
end
class FormulaConflictError < RuntimeError
attr_reader :formula, :conflicts
def initialize(formula, conflicts)
@formula = formula
@conflicts = conflicts
super message
end
def conflict_message(conflict)
message = []
message << " #{conflict.name}"
message << ": because #{conflict.reason}" if conflict.reason
message.join
end
def message
message = []
2015-05-27 22:16:48 +08:00
message << "Cannot install #{formula.full_name} because conflicting formulae are installed.\n"
message.concat conflicts.map { |c| conflict_message(c) } << ""
message << <<-EOS.undent
Please `brew unlink #{conflicts.map(&:name)*' '}` before continuing.
Unlinking removes a formula's symlinks from #{HOMEBREW_PREFIX}. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.
EOS
message.join("\n")
end
end
class BuildError < RuntimeError
attr_reader :formula, :env
def initialize(formula, cmd, args, env)
@formula = formula
@env = env
2011-03-14 15:48:35 -07:00
args = args.map{ |arg| arg.to_s.gsub " ", "\\ " }.join(" ")
super "Failed executing: #{cmd} #{args}"
end
def issues
@issues ||= fetch_issues
end
def fetch_issues
GitHub.issues_for_formula(formula.name)
rescue GitHub::RateLimitExceededError => e
opoo e.message
[]
end
def dump
if not ARGV.verbose?
puts
puts "#{Tty.red}READ THIS#{Tty.reset}: #{Tty.em}#{OS::ISSUES_URL}#{Tty.reset}"
if formula.tap?
case formula.tap
when "homebrew/homebrew-boneyard"
puts "#{formula} was moved to homebrew-boneyard because it has unfixable issues."
puts "Please do not file any issues about this. Sorry!"
else
puts "If reporting this issue please do so at (not Homebrew/homebrew):"
puts " https://github.com/#{formula.tap}/issues"
end
end
else
2014-04-26 23:31:39 -07:00
require 'cmd/config'
2012-09-27 15:39:16 -04:00
require 'cmd/--env'
ohai "Formula"
puts "Tap: #{formula.tap}" if formula.tap?
puts "Path: #{formula.path}"
2012-09-27 15:39:16 -04:00
ohai "Configuration"
2014-12-30 23:33:50 -05:00
Homebrew.dump_verbose_config
2012-09-27 15:39:16 -04:00
ohai "ENV"
Homebrew.dump_build_env(env)
puts
2015-05-27 22:16:48 +08:00
onoe "#{formula.full_name} #{formula.version} did not build"
2015-04-25 22:07:06 -04:00
unless (logs = Dir["#{formula.logs}/*"]).empty?
puts "Logs:"
puts logs.map{|fn| " #{fn}"}.join("\n")
end
2012-09-27 15:39:16 -04:00
end
2012-08-13 09:50:15 -04:00
puts
unless RUBY_VERSION < "1.8.7" || issues.empty?
puts "These open issues may also help:"
puts issues.map{ |i| "#{i['title']} #{i['html_url']}" }.join("\n")
end
if MacOS.version >= "10.11"
require "cmd/doctor"
opoo Checks.new.check_for_unsupported_osx
end
end
end
# raised by CompilerSelector if the formula fails with all of
# the compilers available on the user's system
class CompilerSelectionError < RuntimeError
def initialize(formula)
super <<-EOS.undent
2015-05-27 22:16:48 +08:00
#{formula.full_name} cannot be built with any available compilers.
To install this formula, you may need to:
brew install gcc
EOS
end
end
# Raised in Resource.fetch
class DownloadError < RuntimeError
2014-12-29 22:51:55 -05:00
def initialize(resource, cause)
super <<-EOS.undent
Failed to download resource #{resource.download_name.inspect}
2014-12-29 22:51:55 -05:00
#{cause.message}
EOS
2014-12-29 22:51:55 -05:00
set_backtrace(cause.backtrace)
end
end
# raised in CurlDownloadStrategy.fetch
class CurlDownloadStrategyError < RuntimeError
def initialize(url)
case url
when %r[^file://(.+)]
super "File does not exist: #{$1}"
else
super "Download failed: #{url}"
end
end
end
# raised by safe_system in utils.rb
class ErrorDuringExecution < RuntimeError
def initialize(cmd, args=[])
args = args.map { |a| a.to_s.gsub " ", "\\ " }.join(" ")
super "Failure while executing: #{cmd} #{args}"
end
end
# raised by Pathname#verify_checksum when "expected" is nil or empty
2013-08-06 21:48:05 -07:00
class ChecksumMissingError < ArgumentError; end
# raised by Pathname#verify_checksum when verification fails
class ChecksumMismatchError < RuntimeError
attr_reader :expected, :hash_type
def initialize fn, expected, actual
@expected = expected
@hash_type = expected.hash_type.to_s.upcase
super <<-EOS.undent
#{@hash_type} mismatch
Expected: #{expected}
Actual: #{actual}
Archive: #{fn}
To retry an incomplete download, remove the file above.
EOS
end
end
class ResourceMissingError < ArgumentError
def initialize(formula, resource)
2015-05-27 22:16:48 +08:00
super "#{formula.full_name} does not define resource #{resource.inspect}"
end
end
class DuplicateResourceError < ArgumentError
def initialize(resource)
super "Resource #{resource.inspect} is defined more than once"
end
end