[rubygems/rubygems] Handle connection refused and Errno::EADDRNOTAVAIL as non-retryable

cd529776d5
This commit is contained in:
David Rodríguez 2025-06-20 13:32:41 +02:00 committed by Hiroshi SHIBATA
parent 46a90f9998
commit c4c646d1bb
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
3 changed files with 20 additions and 7 deletions

View file

@ -88,8 +88,11 @@ module Bundler
raise CertificateFailureError.new(uri)
rescue *HTTP_ERRORS => e
Bundler.ui.trace e
if e.is_a?(SocketError) || e.message.to_s.include?("host down:")
raise NetworkDownError, "Could not reach host #{uri.host}. Check your network " \
if e.is_a?(SocketError) || e.is_a?(Errno::EADDRNOTAVAIL) || e.is_a?(Errno::ENETUNREACH) || e.is_a?(Gem::Net::HTTP::Persistent::Error)
host = uri.host
host_port = "#{host}:#{uri.port}"
host = host_port if filtered_uri.to_s.include?(host_port)
raise NetworkDownError, "Could not reach host #{host}. Check your network " \
"connection and try again."
else
raise HTTPError, "Network error while fetching #{filtered_uri}" \

View file

@ -244,13 +244,23 @@ RSpec.describe Bundler::Fetcher::Downloader do
end
end
context "when error message is about no route to host" do
context "when error is about connection refused" do
let(:error_class) { Gem::Net::HTTP::Persistent::Error }
let(:message) { "connection refused down: http://www.uri-to-fetch.com" }
it "should raise a Bundler::Fetcher::NetworkDownError" do
expect { subject.request(uri, options) }.to raise_error(Bundler::Fetcher::NetworkDownError,
/Could not reach host www.uri-to-fetch.com/)
end
end
context "when error is about no route to host" do
let(:error_class) { SocketError }
let(:message) { "Failed to open TCP connection to www.uri-to-fetch.com:443 " }
it "should raise a Bundler::Fetcher::HTTPError" do
expect { subject.request(uri, options) }.to raise_error(Bundler::HTTPError,
"Network error while fetching http://www.uri-to-fetch.com/api/v2/endpoint (#{message})")
it "should raise a Bundler::Fetcher::NetworkDownError" do
expect { subject.request(uri, options) }.to raise_error(Bundler::Fetcher::NetworkDownError,
/Could not reach host www.uri-to-fetch.com/)
end
end
end

View file

@ -697,7 +697,7 @@ RSpec.describe "bundle install with gem sources" do
end
G
expect(err).to include("Could not fetch specs from http://0.0.0.0:9384/")
expect(err).to eq("Could not reach host 0.0.0.0:9384. Check your network connection and try again.")
expect(err).not_to include("file://")
end