Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less wrapping of network errors #4064

Merged
merged 1 commit into from Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/rubygems/remote_fetcher.rb
Expand Up @@ -51,6 +51,7 @@ def to_s # :nodoc:

class UnknownHostError < FetchError
end
deprecate_constant(:UnknownHostError)

@fetcher = nil

Expand Down Expand Up @@ -262,15 +263,9 @@ def fetch_path(uri, mtime = nil, head = false)
end

data
rescue Timeout::Error
raise UnknownHostError.new('timed out', uri)
rescue IOError, SocketError, SystemCallError,
rescue Timeout::Error, IOError, SocketError, SystemCallError,
*(OpenSSL::SSL::SSLError if Gem::HAVE_OPENSSL) => e
if e.message =~ /getaddrinfo/
raise UnknownHostError.new('no such name', uri)
else
raise FetchError.new("#{e.class}: #{e}", uri)
end
raise FetchError.new("#{e.class}: #{e}", uri)
end

def fetch_s3(uri, mtime = nil, head = false)
Expand Down
38 changes: 38 additions & 0 deletions test/rubygems/test_gem_remote_fetcher.rb
Expand Up @@ -496,6 +496,44 @@ def fetcher.fetch_http(uri, mtime = nil, head = nil)
assert_equal url, e.uri
end

def test_fetch_path_timeout_error
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher

def fetcher.fetch_http(uri, mtime = nil, head = nil)
raise Timeout::Error, 'timed out'
end

url = 'http://example.com/uri'

e = assert_raises Gem::RemoteFetcher::FetchError do
fetcher.fetch_path url
end

assert_match %r{Timeout::Error: timed out \(#{Regexp.escape url}\)\z},
e.message
assert_equal url, e.uri
end

def test_fetch_path_getaddrinfo_error
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher

def fetcher.fetch_http(uri, mtime = nil, head = nil)
raise SocketError, 'getaddrinfo: nodename nor servname provided'
end

url = 'http://example.com/uri'

e = assert_raises Gem::RemoteFetcher::FetchError do
fetcher.fetch_path url
end

assert_match %r{SocketError: getaddrinfo: nodename nor servname provided \(#{Regexp.escape url}\)\z},
e.message
assert_equal url, e.uri
end

def test_fetch_path_openssl_ssl_sslerror
fetcher = Gem::RemoteFetcher.new nil
@fetcher = fetcher
Expand Down