Skip to content

Commit f6ae25e

Browse files
committed
Rescue errors in metadata_cascades_for_dep to prevent PR message loss
When metadata_cascades_for_dep encounters a network error (e.g., GitHub API timeout), it now gracefully handles the failure by returning an empty string and logging the error via suppress_error. This allows the PR message to be assembled without the metadata cascade sections (changelog, commits, releases) but still includes the important intro line and message content. Previously, any error in metadata fetching would propagate up to pr_message's top-level rescue, causing the entire PR body to be discarded and replaced with just the header and footer. Fixes #14904
1 parent a0a2daa commit f6ae25e

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

common/lib/dependabot/pull_request_creator/message_builder.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,9 @@ def metadata_cascades_for_dep(dependency)
801801
vulnerabilities_fixed: vulnerabilities_fixed[dependency.name],
802802
github_redirection_service: github_redirection_service
803803
).to_s
804+
rescue StandardError => e
805+
suppress_error("metadata cascades for #{dependency.name}", e)
806+
""
804807
end
805808

806809
sig { returns(String) }

common/spec/dependabot/pull_request_creator/message_builder_spec.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,9 @@ def commits_details(base:, head:)
11211121
stub_request(:any, /.*/).to_raise(SocketError)
11221122
end
11231123

1124-
it "has a blank message" do
1124+
it "still builds the pr_message without the metadata cascade" do
11251125
expect(pr_message)
1126-
.to eq("")
1126+
.to eq("Bumps [business](https://github.com/gocardless/business) from 1.4.0 to 1.5.0.")
11271127
end
11281128
end
11291129

@@ -1155,6 +1155,20 @@ def commits_details(base:, head:)
11551155
end
11561156
end
11571157

1158+
context "when github.com is unreachable while fetching metadata" do
1159+
before do
1160+
allow_any_instance_of(Dependabot::PullRequestCreator::MessageBuilder::MetadataPresenter)
1161+
.to receive(:to_s)
1162+
.and_raise(SocketError, "Connection refused - connect(2) for \"api.github.com\" port 443")
1163+
end
1164+
1165+
it "still builds the pr_message without the metadata cascade" do
1166+
expect(pr_message).to eq(
1167+
"Bumps [business](https://github.com/gocardless/business) from 1.4.0 to 1.5.0."
1168+
)
1169+
end
1170+
end
1171+
11581172
context "with a relative link in the changelog" do
11591173
before do
11601174
stub_request(

0 commit comments

Comments
 (0)