diff options
Diffstat (limited to 'lib/rubygems/errors.rb')
| -rw-r--r-- | lib/rubygems/errors.rb | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb index 6f2847d548..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. @@ -25,14 +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 @@ -50,26 +53,22 @@ module Gem class MissingSpecVersionError < MissingSpecError attr_reader :specs - def initialize name, requirement, specs - super(name, requirement) + def initialize(name, requirement, specs) @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 @@ -81,14 +80,14 @@ module Gem attr_reader :target - def initialize target, conflicts + def initialize(target, conflicts) @target = target @conflicts = conflicts @name = target.name - reason = conflicts.map { |act, dependencies| + reason = conflicts.map do |act, dependencies| "#{act.full_name} conflicts with #{dependencies.join(", ")}" - }.join ", " + end.join ", " # TODO: improve message by saying who activated `con` @@ -105,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 @@ -137,11 +135,7 @@ 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 @@ -150,7 +144,6 @@ module Gem # data from a source class SourceFetchProblem < ErrorReason - ## # Creates a new SourceFetchProblem for the given +source+ and +error+. @@ -173,13 +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 |
