diff options
Diffstat (limited to 'lib/rubygems/exceptions.rb')
| -rw-r--r-- | lib/rubygems/exceptions.rb | 141 |
1 files changed, 58 insertions, 83 deletions
diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb index b7528761fc..e00a70c662 100644 --- a/lib/rubygems/exceptions.rb +++ b/lib/rubygems/exceptions.rb @@ -1,48 +1,57 @@ # frozen_string_literal: true -# TODO: the documentation in here is terrible. -# -# Each exception needs a brief description and the scenarios where it is -# likely to be raised + +require_relative "unknown_command_spell_checker" ## # Base exception class for RubyGems. All exception raised by RubyGems are a # subclass of this one. -class Gem::Exception < RuntimeError +class Gem::Exception < RuntimeError; end - ## - #-- - # TODO: remove in RubyGems 3, nobody sets this +class Gem::CommandLineError < Gem::Exception; end - attr_accessor :source_exception # :nodoc: +class Gem::UnknownCommandError < Gem::Exception + attr_reader :unknown_command -end + def initialize(unknown_command) + self.class.attach_correctable -class Gem::CommandLineError < Gem::Exception; end + @unknown_command = unknown_command + super("Unknown command #{unknown_command}") + end + + def self.attach_correctable + return if method_defined?(:corrections) + + if defined?(DidYouMean) && DidYouMean.respond_to?(:correct_error) + DidYouMean.correct_error(Gem::UnknownCommandError, Gem::UnknownCommandSpellChecker) + end + end +end class Gem::DependencyError < Gem::Exception; end class Gem::DependencyRemovalException < Gem::Exception; end ## -# Raised by Gem::Resolver when a Gem::Dependency::Conflict reaches the -# toplevel. Indicates which dependencies were incompatible through #conflict -# and #conflicting_dependencies +# Raised by Gem::Resolver when dependency resolution fails. class Gem::DependencyResolutionError < Gem::DependencyError + def initialize(conflict) + @explanation = conflict.explanation + super @explanation + end - attr_reader :conflict - - def initialize conflict - @conflict = conflict - a, b = conflicting_dependencies + def explanation + @explanation + end - super "conflicting dependencies #{a} and #{b}\n#{@conflict.explanation}" + def conflict + nil end def conflicting_dependencies - @conflict.conflicting_dependencies + [] end - end ## @@ -52,6 +61,13 @@ class Gem::GemNotInHomeException < Gem::Exception attr_accessor :spec end +### +# Raised when removing a gem with the uninstall command fails + +class Gem::UninstallError < Gem::Exception + attr_accessor :spec +end + class Gem::DocumentError < Gem::Exception; end ## @@ -63,15 +79,13 @@ class Gem::EndOfYAMLException < Gem::Exception; end # operating on the given directory. class Gem::FilePermissionError < Gem::Exception - attr_reader :directory - def initialize directory + def initialize(directory) @directory = directory super "You don't have write permissions for the #{directory} directory." end - end ## @@ -82,17 +96,13 @@ end class Gem::GemNotFoundException < Gem::Exception; end -## -# Raised by the DependencyInstaller when a specific gem cannot be found - class Gem::SpecificGemNotFoundException < Gem::GemNotFoundException - ## # Creates a new SpecificGemNotFoundException for a gem with the given +name+ # and +version+. Any +errors+ encountered when attempting to find the gem # are also stored. - def initialize(name, version, errors=nil) + def initialize(name, version, errors = nil) super "Could not find a valid gem '#{name}' (#{version}) locally or in a repository" @name = name @@ -114,46 +124,12 @@ class Gem::SpecificGemNotFoundException < Gem::GemNotFoundException # Errors encountered attempting to find the gem. attr_reader :errors - end -## -# Raised by Gem::Resolver when dependencies conflict and create the -# inability to find a valid possible spec for a request. - -class Gem::ImpossibleDependenciesError < Gem::Exception - - attr_reader :conflicts - attr_reader :request - - def initialize request, conflicts - @request = request - @conflicts = conflicts - - super build_message - end - - def build_message # :nodoc: - requester = @request.requester - requester = requester ? requester.spec.full_name : 'The user' - dependency = @request.dependency - - message = "#{requester} requires #{dependency} but it conflicted:\n".dup - - @conflicts.each do |_, conflict| - message << conflict.explanation - end - - message - end - - def dependency - @request.dependency - end - -end +Gem.deprecate_constant :SpecificGemNotFoundException class Gem::InstallError < Gem::Exception; end + class Gem::RuntimeRequirementNotMetError < Gem::InstallError attr_accessor :suggestion def message @@ -196,25 +172,31 @@ class Gem::RubyVersionMismatch < Gem::Exception; end class Gem::VerificationError < Gem::Exception; end ## +# Raised by Gem::WebauthnListener when an error occurs during security +# device verification. + +class Gem::WebauthnVerificationError < Gem::Exception + def initialize(message) + super "Security device verification failed: #{message}" + end +end + +## # Raised to indicate that a system exit should occur with the specified # exit_code class Gem::SystemExitException < SystemExit - ## # The exit code for the process - attr_accessor :exit_code + alias_method :exit_code, :status ## # Creates a new SystemExitException with the given +exit_code+ def initialize(exit_code) - @exit_code = exit_code - - super "Exiting RubyGems with exit_code #{exit_code}" + super exit_code, "Exiting RubyGems with exit_code #{exit_code}" end - end ## @@ -222,7 +204,6 @@ end # there is no spec. class Gem::UnsatisfiableDependencyError < Gem::DependencyError - ## # The unsatisfiable dependency. This is a # Gem::Resolver::DependencyRequest, not a Gem::Dependency @@ -238,10 +219,10 @@ class Gem::UnsatisfiableDependencyError < Gem::DependencyError # Creates a new UnsatisfiableDependencyError for the unsatisfiable # Gem::Resolver::DependencyRequest +dep+ - def initialize dep, platform_mismatch=nil - if platform_mismatch and !platform_mismatch.empty? - plats = platform_mismatch.map { |x| x.platform.to_s }.sort.uniq - super "Unable to resolve dependency: No match for '#{dep}' on this platform. Found: #{plats.join(', ')}" + def initialize(dep, platform_mismatch = nil) + if platform_mismatch && !platform_mismatch.empty? + plats = platform_mismatch.map {|x| x.platform.to_s }.sort.uniq + super "Unable to resolve dependency: No match for '#{dep}' on this platform. Found: #{plats.join(", ")}" else if dep.explicit? super "Unable to resolve dependency: user requested '#{dep}'" @@ -267,10 +248,4 @@ class Gem::UnsatisfiableDependencyError < Gem::DependencyError def version @dependency.requirement end - end - -## -# Backwards compatible typo'd exception class for early RubyGems 2.0.x - -Gem::UnsatisfiableDepedencyError = Gem::UnsatisfiableDependencyError # :nodoc: |
