From 5108254e9f3e7979bcb81309e807232d3d8f4766 Mon Sep 17 00:00:00 2001 From: Roland Walker Date: Thu, 18 Dec 2014 21:14:41 -0500 Subject: [PATCH] strip various exception classes from homebrew-fork --- .../Library/Homebrew/exceptions.rb | 215 +----------------- .../Library/Homebrew/extend/ARGV.rb | 8 +- .../Library/Homebrew/extend/ENV/shared.rb | 2 +- .../Library/Homebrew/resource.rb | 2 +- 4 files changed, 9 insertions(+), 218 deletions(-) diff --git a/lib/homebrew-fork/Library/Homebrew/exceptions.rb b/lib/homebrew-fork/Library/Homebrew/exceptions.rb index 78a9ea0cbb6..9d09b8b860e 100644 --- a/lib/homebrew-fork/Library/Homebrew/exceptions.rb +++ b/lib/homebrew-fork/Library/Homebrew/exceptions.rb @@ -1,203 +1,3 @@ -class UsageError < RuntimeError; end -class FormulaUnspecifiedError < UsageError; end -class KegUnspecifiedError < UsageError; end - -class MultipleVersionsInstalledError < RuntimeError - attr_reader :name - - def initialize name - @name = name - super "#{name} has multiple installed versions" - end -end - -class NotAKegError < RuntimeError; end - -class NoSuchKegError < RuntimeError - attr_reader :name - - 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 - -class FormulaSpecificationError < StandardError; end - -class FormulaUnavailableError < RuntimeError - attr_reader :name - - def initialize name - @name = name - end - - def to_s - "No available formula for #{name}" - end -end - -class TapFormulaUnavailableError < FormulaUnavailableError - attr_reader :user, :repo, :shortname - - def initialize name - super - @user, @repo, @shortname = name.split("/", 3) - end - - def to_s; <<-EOS.undent - No available formula for #{shortname} - Please tap it and then try again: brew tap #{user}/#{repo} - 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 - -class CannotInstallFormulaError < RuntimeError; end - -class FormulaAlreadyInstalledError < RuntimeError; end - -class FormulaInstallationAlreadyAttemptedError < RuntimeError - def initialize(formula) - super "Formula installation already attempted: #{formula.name}" - 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 = [] - message << "Cannot install #{formula.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 - 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? - puts "If reporting this issue please do so at (not Homebrew/homebrew):" - puts " https://github.com/#{formula.tap}/issues" - end - else - require 'cmd/config' - require 'cmd/--env' - - unless formula.core_formula? - ohai "Formula" - puts "Tap: #{formula.tap}" - puts "Path: #{formula.path}" - end - ohai "Configuration" - Homebrew.dump_build_config - ohai "ENV" - Homebrew.dump_build_env(env) - puts - onoe "#{formula.name} #{formula.version} did not build" - unless (logs = Dir["#{HOMEBREW_LOGS}/#{formula.name}/*"]).empty? - puts "Logs:" - puts logs.map{|fn| " #{fn}"}.join("\n") - end - end - 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 - 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 - #{formula.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 - def initialize(resource, e) - super <<-EOS.undent - Failed to download resource #{resource.download_name.inspect} - #{e.message} - EOS - end -end - -# raised in CurlDownloadStrategy.fetch -class CurlDownloadStrategyError < RuntimeError; end - # raised by safe_system in utils.rb class ErrorDuringExecution < RuntimeError def initialize(cmd, args=[]) @@ -206,6 +6,9 @@ class ErrorDuringExecution < RuntimeError end end +# raised in CurlDownloadStrategy.fetch +class CurlDownloadStrategyError < RuntimeError; end + # raised by Pathname#verify_checksum when "expected" is nil or empty class ChecksumMissingError < ArgumentError; end @@ -226,15 +29,3 @@ class ChecksumMismatchError < RuntimeError EOS end end - -class ResourceMissingError < ArgumentError - def initialize(formula, resource) - super "#{formula.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 diff --git a/lib/homebrew-fork/Library/Homebrew/extend/ARGV.rb b/lib/homebrew-fork/Library/Homebrew/extend/ARGV.rb index 7296bf2ba6c..c618ad4815b 100644 --- a/lib/homebrew-fork/Library/Homebrew/extend/ARGV.rb +++ b/lib/homebrew-fork/Library/Homebrew/extend/ARGV.rb @@ -24,7 +24,7 @@ module HomebrewArgvExtension rack = HOMEBREW_CELLAR/canonical_name dirs = rack.directory? ? rack.subdirs : [] - raise NoSuchKegError.new(canonical_name) if dirs.empty? + raise RuntimeError.new(canonical_name) if dirs.empty? linked_keg_ref = HOMEBREW_LIBRARY.join("LinkedKegs", canonical_name) opt_prefix = HOMEBREW_PREFIX.join("opt", canonical_name) @@ -39,9 +39,9 @@ module HomebrewArgvExtension elsif (prefix = Formulary.factory(canonical_name).prefix).directory? Keg.new(prefix) else - raise MultipleVersionsInstalledError.new(canonical_name) + raise RuntimeError.new(canonical_name) end - rescue FormulaUnavailableError + rescue RuntimeError raise <<-EOS.undent Multiple kegs installed to #{rack} However we don't know which one you refer to. @@ -56,7 +56,7 @@ module HomebrewArgvExtension @n=index arg end def next - at @n+1 or raise UsageError + at @n+1 or raise RuntimeError end def value arg diff --git a/lib/homebrew-fork/Library/Homebrew/extend/ENV/shared.rb b/lib/homebrew-fork/Library/Homebrew/extend/ENV/shared.rb index 85a2c9a40ff..640f80b6fa0 100644 --- a/lib/homebrew-fork/Library/Homebrew/extend/ENV/shared.rb +++ b/lib/homebrew-fork/Library/Homebrew/extend/ENV/shared.rb @@ -158,7 +158,7 @@ module SharedEnvExtension brew install #{gcc_name} EOS end - rescue FormulaUnavailableError + rescue RuntimeError raise <<-EOS.undent Homebrew GCC requested, but formula #{gcc_name} not found! You may need to: brew tap homebrew/versions diff --git a/lib/homebrew-fork/Library/Homebrew/resource.rb b/lib/homebrew-fork/Library/Homebrew/resource.rb index 97dcdf97643..b671758ba97 100644 --- a/lib/homebrew-fork/Library/Homebrew/resource.rb +++ b/lib/homebrew-fork/Library/Homebrew/resource.rb @@ -83,7 +83,7 @@ class Resource HOMEBREW_CACHE.mkpath downloader.fetch rescue ErrorDuringExecution, CurlDownloadStrategyError => e - raise DownloadError.new(self, e) + raise RuntimeError.new else cached_download end