summaryrefslogtreecommitdiff
path: root/lib/rubygems/exceptions.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2021-01-04 10:09:05 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-01-04 13:14:43 +0900
commit5537adf719a37a30b17d39111cc03700f353aa2d (patch)
tree7523de9950b8a0118143f4ee0029aee17d043e04 /lib/rubygems/exceptions.rb
parent35c3a24c8cbcccff1108079360e2063fc354b4bd (diff)
Track RubyGems master(3.3.0.dev) branch at 55634a8af18a52df86c4275d70fa1179118bcc20
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4021
Diffstat (limited to 'lib/rubygems/exceptions.rb')
-rw-r--r--lib/rubygems/exceptions.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb
index 804863f693..55755ddfba 100644
--- a/lib/rubygems/exceptions.rb
+++ b/lib/rubygems/exceptions.rb
@@ -1,6 +1,7 @@
# frozen_string_literal: true
require 'rubygems/deprecate'
+require 'rubygems/unknown_command_spell_checker'
##
# Base exception class for RubyGems. All exception raised by RubyGems are a
@@ -9,6 +10,30 @@ 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 defined?(@attached)
+
+ if defined?(DidYouMean::SPELL_CHECKERS) && defined?(DidYouMean::Correctable)
+ DidYouMean::SPELL_CHECKERS['Gem::UnknownCommandError'] =
+ Gem::UnknownCommandSpellChecker
+
+ prepend DidYouMean::Correctable
+ end
+
+ @attached = true
+ end
+end
+
class Gem::DependencyError < Gem::Exception; end
class Gem::DependencyRemovalException < Gem::Exception; end