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.rb37
1 files changed, 10 insertions, 27 deletions
diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb
index 2cd18e2e20..4bbc5217e0 100644
--- a/lib/rubygems/errors.rb
+++ b/lib/rubygems/errors.rb
@@ -1,4 +1,5 @@
# frozen_string_literal: true
+
#--
# This file contains all the various exceptions and other errors that are used
# inside of RubyGems.
@@ -13,13 +14,11 @@ module Gem
# already activated gems or that RubyGems is otherwise unable to activate.
class LoadError < ::LoadError
-
# Name of gem
attr_accessor :name
# Version requirement of gem
attr_accessor :requirement
-
end
##
@@ -27,15 +26,16 @@ module Gem
# 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)
+ def initialize(name, requirement, extra_message = nil)
@name = name
@requirement = requirement
+ @extra_message = extra_message
+ super(message)
end
def message # :nodoc:
build_message +
- "Checked in 'GEM_PATH=#{Gem.path.join(File::PATH_SEPARATOR)}', execute `gem env` for more information"
+ "Checked in 'GEM_PATH=#{Gem.path.join(File::PATH_SEPARATOR)}' #{@extra_message}, execute `gem env` for more information"
end
private
@@ -44,7 +44,6 @@ module Gem
total = Gem::Specification.stubs.size
"Could not find '#{name}' (#{requirement}) among #{total} total gem(s)\n"
end
-
end
##
@@ -52,30 +51,24 @@ module Gem
# 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
+ super(name, requirement)
end
private
def build_message
- if name == "bundler" && message = Gem::BundlerVersionFinder.missing_version_message
- return message
- end
names = specs.map(&:full_name)
- "Could not find '#{name}' (#{requirement}) - did find: [#{names.join ','}]\n"
+ "Could not find '#{name}' (#{requirement}) - did find: [#{names.join ","}]\n"
end
-
end
# Raised when there are conflicting gem specs loaded
class ConflictError < LoadError
-
##
# A Hash mapping conflicting specifications to the dependencies that
# caused the conflict
@@ -100,7 +93,6 @@ module Gem
super("Unable to activate #{target.full_name}, because #{reason}")
end
-
end
class ErrorReason; end
@@ -112,7 +104,6 @@ module Gem
# in figuring out why a gem couldn't be installed.
#
class PlatformMismatch < ErrorReason
-
##
# the name of the gem
attr_reader :name
@@ -144,13 +135,8 @@ module Gem
##
# A wordy description of the error.
def wordy
- "Found %s (%s), but was for platform%s %s" %
- [@name,
- @version,
- @platforms.size == 1 ? '' : 's',
- @platforms.join(' ,')]
+ format("Found %s (%s), but was for platform%s %s", @name, @version, @platforms.size == 1 ? "" : "s", @platforms.join(" ,"))
end
-
end
##
@@ -158,7 +144,6 @@ module Gem
# data from a source
class SourceFetchProblem < ErrorReason
-
##
# Creates a new SourceFetchProblem for the given +source+ and +error+.
@@ -181,14 +166,12 @@ module Gem
# An English description of the error.
def wordy
- @source.uri.password = 'REDACTED' unless @source.uri.password.nil?
- "Unable to download data from #{@source.uri} - #{@error.message}"
+ "Unable to download data from #{Gem::Uri.redact(@source.uri)} - #{@error.message}"
end
##
# The "exception" alias allows you to call raise on a SourceFetchProblem.
- alias exception error
-
+ alias_method :exception, :error
end
end