summaryrefslogtreecommitdiff
path: root/lib/rubygems/remote_fetcher.rb
diff options
context:
space:
mode:
authorDaniel Niknam <mhmd.niknam@gmail.com>2021-08-22 20:06:02 +1000
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-08-31 19:06:14 +0900
commit589377fbdce9d281041535e3bf63f008689bb776 (patch)
tree7eb9671d26a73517834f2e42ab206462229c5c57 /lib/rubygems/remote_fetcher.rb
parenta508693f06aefe30d2d83c9617541722ba6c8d66 (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/remote_fetcher.rb')
-rw-r--r--lib/rubygems/remote_fetcher.rb35
1 files changed, 13 insertions, 22 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