diff options
Diffstat (limited to 'lib/rubygems/exceptions.rb')
| -rw-r--r-- | lib/rubygems/exceptions.rb | 108 |
1 files changed, 49 insertions, 59 deletions
diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb index 804863f693..e00a70c662 100644 --- a/lib/rubygems/exceptions.rb +++ b/lib/rubygems/exceptions.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require 'rubygems/deprecate' +require_relative "unknown_command_spell_checker" ## # Base exception class for RubyGems. All exception raised by RubyGems are a @@ -9,27 +9,48 @@ class Gem::Exception < RuntimeError; end class Gem::CommandLineError < Gem::Exception; end +class Gem::UnknownCommandError < Gem::Exception + attr_reader :unknown_command + + def initialize(unknown_command) + self.class.attach_correctable + + @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 - attr_reader :conflict - def initialize(conflict) - @conflict = conflict - a, b = conflicting_dependencies + @explanation = conflict.explanation + super @explanation + end + + 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 @@ -75,16 +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 @@ -108,41 +126,10 @@ class Gem::SpecificGemNotFoundException < Gem::GemNotFoundException 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 @@ -185,6 +172,16 @@ 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 @@ -192,15 +189,13 @@ 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 @@ -224,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? + 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(', ')}" + 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}'" @@ -254,8 +249,3 @@ class Gem::UnsatisfiableDependencyError < Gem::DependencyError @dependency.requirement end end - -## -# Backwards compatible typo'd exception class for early RubyGems 2.0.x - -Gem::UnsatisfiableDepedencyError = Gem::UnsatisfiableDependencyError # :nodoc: |
