Skip to content

Commit

Permalink
Adds handler to fix private registries timeout and socket errors (#11523
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sachin-sandhu authored Feb 7, 2025
1 parent 0e52414 commit 2defbee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions terraform/lib/dependabot/terraform/registry_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ def http_get(url)
url: url.to_s,
headers: headers_for(hostname)
)
rescue Excon::Error::Socket, Excon::Error::Timeout
raise PrivateSourceBadResponse, hostname
end

sig { params(url: URI::Generic).returns(Excon::Response) }
Expand Down
10 changes: 10 additions & 0 deletions terraform/spec/dependabot/terraform/registry_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,16 @@
end
end

context "when the metadata endpoint is not reachable with Timeout error" do
it "raises an error" do
stub_request(:get, metadata).to_raise(Excon::Error::Timeout)

expect do
client.service_url_for("modules.v1")
end.to raise_error(Dependabot::PrivateSourceBadResponse)
end
end

context "when the service url is not available" do
it "raises an error" do
stub_request(:get, metadata).and_return(body: { "modules.v1": "/v1/modules/" }.to_json)
Expand Down

0 comments on commit 2defbee

Please # to comment.