diff --git a/patches/release-please+17.3.0.patch b/patches/release-please+17.3.0.patch index aefd169e79..f2a5ba70af 100644 --- a/patches/release-please+17.3.0.patch +++ b/patches/release-please+17.3.0.patch @@ -13,13 +13,13 @@ } catch (err) { - if (err.status !== 502) { -+ // Only commit-history reads opt in to transient HTTP-200 errors. -+ const retryInternalError = options?.retryInternalErrors && ++ // Only commit-history reads opt in to gateway timeouts and transient HTTP-200 errors. ++ const retryHistoryError = options?.retryHistoryErrors && (err.status === 504 || + err instanceof graphql_1.GraphqlResponseError && + err.errors.length > 0 && + err.errors.every(error => typeof error.message === 'string' && -+ error.message.startsWith('Something went wrong while executing your query')); -+ if (err.status !== 502 && !retryInternalError) { ++ error.message.startsWith('Something went wrong while executing your query'))); ++ if (err.status !== 502 && !retryHistoryError) { throw err; } if (maxRetries === 0) { @@ -27,7 +27,7 @@ throw err; } - this.logger.info(`received 502 error, ${maxRetries} attempts remaining`); -+ this.logger.info(`received ${err.status === 502 ? '502' : 'internal GraphQL'} error, ${maxRetries} attempts remaining`); ++ this.logger.info(`received ${err.status === 502 || err.status === 504 ? err.status : 'internal GraphQL'} error, ${maxRetries} attempts remaining`); } maxRetries -= 1; if (maxRetries >= 0) { @@ -78,7 +78,7 @@ query, ...params, - }); -+ }, { retryInternalErrors: true }); ++ }, { retryHistoryErrors: true }); if (!response) { this.logger.warn(`Did not receive a response for query: ${query}`, params); return null; diff --git a/scripts/lib/release-proposal.mjs b/scripts/lib/release-proposal.mjs index 386238ac36..24877297d5 100644 --- a/scripts/lib/release-proposal.mjs +++ b/scripts/lib/release-proposal.mjs @@ -15,8 +15,12 @@ const patch = fileURLToPath( export function describeReleaseProposalError(error) { if (!(error instanceof Error)) return String(error); - const description = error.message || error.name || "Unknown error"; const status = error.status; + const description = /^\s*<(?:!doctype\s+html\b|html[\s>])/iu.test( + error.message, + ) + ? "GitHub returned an HTML error response" + : error.message || error.name || "Unknown error"; return Number.isInteger(status) && status >= 400 && status <= 599 ? `${description} (HTTP ${status})` : description; diff --git a/tests/boundary/filesystem/releaseProposal.test.ts b/tests/boundary/filesystem/releaseProposal.test.ts index 98d16a7074..53bdea7c35 100644 --- a/tests/boundary/filesystem/releaseProposal.test.ts +++ b/tests/boundary/filesystem/releaseProposal.test.ts @@ -46,6 +46,18 @@ it("reports an HTTP status when a release proposal error has no message", () => expect(describeReleaseProposalError(new Error("broken"))).toBe("broken"); }); +it("reports a gateway error without logging the HTML response page", () => { + const failure = Object.assign( + new Error("\nUnicorn!"), + { + status: 504, + }, + ); + expect(describeReleaseProposalError(failure)).toBe( + "GitHub returned an HTML error response (HTTP 504)", + ); +}); + beforeAll(async () => { upstream = await import("release-please"); githubRuntime = require("release-please/build/src/github.js"); @@ -303,6 +315,7 @@ type HistoryFailure = { cursor?: string; errors: { message: string; type?: string }[]; status?: number; + html?: string; }; const internalError = { message: @@ -482,6 +495,11 @@ async function releaseFixture({ const failure = failures[0]; if (failure && failure.cursor === query.variables.cursor) { failures.shift(); + if (failure.html !== undefined) + return new Response(failure.html, { + status: failure.status ?? 504, + headers: { "content-type": "text/html; charset=utf-8" }, + }); return respond( { ...historyPage(commits, query.variables, pullRequest), @@ -998,9 +1016,15 @@ it.each([ status: 200, }, { name: "HTTP 502 error", error: internalError, status: 502 }, + { + name: "HTTP 504 HTML error", + error: internalError, + status: 504, + html: "Unicorn!", + }, ])( "retries the same history cursor after $name and discards partial data", - async ({ error, status }) => { + async ({ error, status, html }) => { const sleep = vi .spyOn(githubRuntime, "sleepInMs") .mockResolvedValue(undefined); @@ -1012,7 +1036,14 @@ it.each([ commits.push({ sha: baseline, message: "chore: release 6.7.0", files: [] }); const fixture = await releaseFixture({ commits, - historyFailures: [{ cursor: "10", errors: [error], status }], + historyFailures: [ + { + cursor: "10", + errors: [error], + status, + ...(html === undefined ? {} : { html }), + }, + ], }); const candidates = await fixture.manifest.buildPullRequests(); const body = candidates[0]?.body.toString();