summaryrefslogtreecommitdiff
path: root/lib/rubygems/errors.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems/errors.rb')
-rw-r--r--lib/rubygems/errors.rb43
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb
index 8304647546..f607d14938 100644
--- a/lib/rubygems/errors.rb
+++ b/lib/rubygems/errors.rb
@@ -20,6 +20,49 @@ module Gem
attr_accessor :requirement
end
+ ##
+ # Raised when trying to activate a gem, and that gem does not exist on the
+ # system. Instead of rescuing from this class, make sure to rescue from the
+ # superclass Gem::LoadError to catch all types of load errors.
+ class MissingSpecError < Gem::LoadError
+ def initialize name, requirement
+ @name = name
+ @requirement = requirement
+ end
+
+ def message # :nodoc:
+ build_message +
+ "Checked in 'GEM_PATH=#{Gem.path.join(File::PATH_SEPARATOR)}', execute `gem env` for more information"
+ end
+
+ private
+
+ def build_message
+ total = Gem::Specification.stubs.size
+ "Could not find '#{name}' (#{requirement}) among #{total} total gem(s)\n"
+ end
+ end
+
+ ##
+ # Raised when trying to activate a gem, and the gem exists on the system, but
+ # not the requested version. Instead of rescuing from this class, make sure to
+ # rescue from the superclass Gem::LoadError to catch all types of load errors.
+ class MissingSpecVersionError < MissingSpecError
+ attr_reader :specs
+
+ def initialize name, requirement, specs
+ super(name, requirement)
+ @specs = specs
+ end
+
+ private
+
+ def build_message
+ names = specs.map(&:full_name)
+ "Could not find '#{name}' (#{requirement}) - did find: [#{names.join ','}]\n"
+ end
+ end
+
# Raised when there are conflicting gem specs loaded
class ConflictError < LoadError