brew/Library/Homebrew/exceptions.rb

282 lines
7.1 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
msg = "invalid attribute: #{attr}"
msg << " (#{value.inspect})" unless value.empty?
super msg
end
end
2013-08-06 21:48:05 -07:00
class FormulaSpecificationError < StandardError; end
class FormulaUnavailableError < RuntimeError
attr_reader :name
attr_accessor :dependent
def dependent_s
"(dependency of #{dependent})" if dependent and dependent != name
end
def to_s
if name =~ HOMEBREW_TAP_FORMULA_REGEX then <<-EOS.undent
No available formula for #$3 #{dependent_s}
Please tap it and then try again: brew tap #$1/#$2
EOS
else
"No available formula for #{name} #{dependent_s}"
end
end
2010-11-12 20:59:53 -08:00
def initialize name
@name = name
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
module Homebrew
class InstallationError < RuntimeError
attr_reader :formula
2010-11-12 20:59:53 -08:00
def initialize formula, message=""
super message
@formula = formula
end
end
end
2013-08-06 21:48:05 -07:00
class CannotInstallFormulaError < RuntimeError; end
2013-08-06 21:48:05 -07:00
class FormulaAlreadyInstalledError < RuntimeError; end
class FormulaInstallationAlreadyAttemptedError < Homebrew::InstallationError
def message
"Formula installation already attempted: #{formula}"
end
end
class UnsatisfiedDependencyError < Homebrew::InstallationError
def initialize(f, dep)
super f, <<-EOS.undent
#{f} dependency #{dep} not installed with:
#{dep.missing_options * ', '}
EOS
end
end
class UnsatisfiedRequirements < Homebrew::InstallationError
attr_reader :reqs
def initialize formula, reqs
@reqs = reqs
message = (reqs.length == 1) \
? "An unsatisfied requirement failed this build." \
: "Unsatisifed requirements failed this build."
super formula, message
end
end
class IncompatibleCxxStdlibs < Homebrew::InstallationError
def initialize(f, dep, wrong, right)
super f, <<-EOS.undent
#{f} dependency #{dep} was built with the following
C++ standard library: #{wrong.type_string} (from #{wrong.compiler})
This is incompatible with the standard library being used
to build #{f}: #{right.type_string} (from #{right.compiler})
Please reinstall #{dep} using a compatible compiler.
hint: Check https://github.com/Homebrew/homebrew/wiki/C++-Standard-Libraries
EOS
end
end
class FormulaConflictError < Homebrew::InstallationError
attr_reader :f, :conflicts
def initialize(f, conflicts)
@f = f
@conflicts = conflicts
super f, message
end
def conflict_message(conflict)
message = []
message << " #{conflict.name}"
message << ": because #{conflict.reason}" if conflict.reason
message.join
end
def message
message = []
message << "Cannot install #{f.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 < Homebrew::InstallationError
attr_reader :exit_status, :command, :env
def initialize formula, cmd, args, es
@command = cmd
@env = ENV.to_hash
@exit_status = es.exitstatus rescue 1
2011-03-14 15:48:35 -07:00
args = args.map{ |arg| arg.to_s.gsub " ", "\\ " }.join(" ")
super formula, "Failed executing: #{command} #{args}"
end
def was_running_configure?
@command == './configure'
end
def issues
@issues ||= GitHub.issues_for_formula(formula.name)
end
def dump
if not ARGV.verbose?
puts
puts "#{Tty.red}READ THIS#{Tty.reset}: #{Tty.em}#{ISSUES_URL}#{Tty.reset}"
if formula.tap?
user, repo = formula.tap.split '/'
tap_issues_url = "https://github.com/#{user}/homebrew-#{repo}/issues"
puts "If reporting this issue please do so at (not Homebrew/homebrew):"
puts " #{tap_issues_url}"
end
else
2012-09-27 15:39:16 -04:00
require 'cmd/--config'
require 'cmd/--env'
unless formula.core_formula?
ohai "Formula"
puts "Tap: #{formula.tap}"
puts "Path: #{formula.path.realpath}"
end
2012-09-27 15:39:16 -04:00
ohai "Configuration"
Homebrew.dump_build_config
ohai "ENV"
Homebrew.dump_build_env(env)
puts
onoe "#{formula.name} did not build"
2013-10-31 16:58:55 -07:00
unless (logs = Dir["#{HOMEBREW_LOGS}/#{formula}/*"]).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.6" || issues.empty?
puts "These open issues may also help:"
puts issues.map{ |i| "#{i['title']} (#{i['html_url']})" }.join("\n")
end
end
end
# raised by CompilerSelector if the formula fails with all of
# the compilers available on the user's system
class CompilerSelectionError < Homebrew::InstallationError
def initialize f
super f, <<-EOS.undent
#{f.name} cannot be built with any available compilers.
2013-09-27 20:32:44 -07:00
To install this formula, you may need to:
brew install apple-gcc42
EOS
end
end
# raised in CurlDownloadStrategy.fetch
2013-08-06 21:48:05 -07:00
class CurlDownloadStrategyError < RuntimeError; end
# raised by safe_system in utils.rb
2013-08-06 21:48:05 -07:00
class ErrorDuringExecution < RuntimeError; 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_accessor :advice
attr_reader :expected, :actual, :hash_type
def initialize expected, actual
@expected = expected
@actual = actual
@hash_type = expected.hash_type.to_s.upcase
super <<-EOS.undent
#{@hash_type} mismatch
Expected: #{@expected}
Actual: #{@actual}
EOS
end
def to_s
super + advice.to_s
end
end
class ResourceMissingError < ArgumentError
def initialize formula, resource
@formula = formula
@resource = resource
end
def to_s
"Formula #{@formula} does not define resource \"#{@resource}\"."
end
end
class DuplicateResourceError < ArgumentError
def initialize resource
@resource = resource
end
def to_s
"Resource \"#{@resource}\" defined more than once."
end
end