diff options
author | Daniel Niknam <[email protected]> | 2021-08-22 20:06:02 +1000 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-08-31 19:06:14 +0900 |
commit | 589377fbdce9d281041535e3bf63f008689bb776 (patch) | |
tree | 7eb9671d26a73517834f2e42ab206462229c5c57 /lib/rubygems | |
parent | a508693f06aefe30d2d83c9617541722ba6c8d66 (diff) |
[rubygems/rubygems] Refactor `Gem::RemoteFetcher::FetchError.build` back to its initialize method
https://github.com/rubygems/rubygems/commit/21dcdd2dc5
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4789
Diffstat (limited to 'lib/rubygems')
-rw-r--r-- | lib/rubygems/remote_fetcher.rb | 35 | ||||
-rw-r--r-- | lib/rubygems/request.rb | 8 |
2 files changed, 17 insertions, 26 deletions
diff --git a/lib/rubygems/remote_fetcher.rb b/lib/rubygems/remote_fetcher.rb index 60c5da090f..ba1c1cb4e7 100644 --- a/lib/rubygems/remote_fetcher.rb +++ b/lib/rubygems/remote_fetcher.rb @@ -22,24 +22,15 @@ class Gem::RemoteFetcher class FetchError < Gem::Exception ## # The URI which was being accessed when the exception happened. - def self.build(message, uri) - original_uri = uri.dup - uri = Gem::PrintableUri.parse_uri(uri) - - if uri.respond_to?(:original_password) && uri.original_password - message = message.sub(uri.original_password, 'REDACTED') - end - - new(message, uri.to_s, original_uri) - end - attr_accessor :uri, :original_uri - def initialize(message, uri, original_uri = nil) - super message + def initialize(message, uri) + @original_uri = uri.dup + uri = Gem::PrintableUri.parse_uri(uri) + + super(uri.valid_uri? && uri.original_password ? message.sub(uri.original_password, 'REDACTED') : message) - @uri = uri - @original_uri = original_uri ? original_uri : uri + @uri = uri.to_s end def to_s # :nodoc: @@ -225,20 +216,20 @@ class Gem::RemoteFetcher head ? response : response.body when Net::HTTPMovedPermanently, Net::HTTPFound, Net::HTTPSeeOther, Net::HTTPTemporaryRedirect then - raise FetchError.build('too many redirects', uri) if depth > 10 + raise FetchError.new('too many redirects', uri) if depth > 10 unless location = response['Location'] - raise FetchError.build("redirecting but no redirect location was given", uri) + raise FetchError.new("redirecting but no redirect location was given", uri) end location = Gem::UriParser.parse_uri location if https?(uri) && !https?(location) - raise FetchError.build("redirecting to non-https resource: #{location}", uri) + raise FetchError.new("redirecting to non-https resource: #{location}", uri) end fetch_http(location, last_modified, head, depth + 1) else - raise FetchError.build("bad response #{response.message} #{response.code}", uri) + raise FetchError.new("bad response #{response.message} #{response.code}", uri) end end @@ -260,21 +251,21 @@ class Gem::RemoteFetcher begin data = Gem::Util.gunzip data rescue Zlib::GzipFile::Error - raise FetchError.build("server did not return a valid file", uri) + raise FetchError.new("server did not return a valid file", uri) end end data rescue Timeout::Error, IOError, SocketError, SystemCallError, *(OpenSSL::SSL::SSLError if Gem::HAVE_OPENSSL) => e - raise FetchError.build("#{e.class}: #{e}", uri) + raise FetchError.new("#{e.class}: #{e}", uri) end def fetch_s3(uri, mtime = nil, head = false) begin public_uri = s3_uri_signer(uri).sign rescue Gem::S3URISigner::ConfigurationError, Gem::S3URISigner::InstanceProfileError => e - raise FetchError.build(e.message, "s3://#{uri.host}") + raise FetchError.new(e.message, "s3://#{uri.host}") end fetch_https public_uri, mtime, head end diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb index d0d9b58dd1..fdc4c55da0 100644 --- a/lib/rubygems/request.rb +++ b/lib/rubygems/request.rb @@ -127,7 +127,7 @@ class Gem::Request @connection_pool.checkout rescue Gem::HAVE_OPENSSL ? OpenSSL::SSL::SSLError : Errno::EHOSTDOWN, Errno::EHOSTDOWN => e - raise Gem::RemoteFetcher::FetchError.build(e.message, uri) + raise Gem::RemoteFetcher::FetchError.new(e.message, uri) end def fetch @@ -228,14 +228,14 @@ class Gem::Request reset connection - raise Gem::RemoteFetcher::FetchError.build('too many bad responses', @uri) if bad_response + raise Gem::RemoteFetcher::FetchError.new('too many bad responses', @uri) if bad_response bad_response = true retry rescue Net::HTTPFatalError verbose "fatal error" - raise Gem::RemoteFetcher::FetchError.build('fatal error', @uri) + raise Gem::RemoteFetcher::FetchError.new('fatal error', @uri) # HACK work around EOFError bug in Net::HTTP # NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible # to install gems. @@ -245,7 +245,7 @@ class Gem::Request requests = @requests[connection.object_id] verbose "connection reset after #{requests} requests, retrying" - raise Gem::RemoteFetcher::FetchError.build('too many connection resets', @uri) if retried + raise Gem::RemoteFetcher::FetchError.new('too many connection resets', @uri) if retried reset connection |