-
Notifications
You must be signed in to change notification settings - Fork 648
Description
Summary
bin/generate-readme.mjs has two edge-case bugs on main:
- Support docs fallback is skipped when HEAD returns HTTP 404.
- README generation can throw when
parse-link-headerreturnsnull.
Both are reproducible on current upstream/main and affect README generation reliability.
Environment
- Repo:
googleapis/google-cloud-node - Script:
bin/generate-readme.mjs - Verified on:
mainata0e6fcbf05292d3fa60c8090295365b1180656bc
Repro 1: 404 fallback mismatch
Why this happens
The script uses validateStatus: () => true, so a 404 response does not throw.
Fallback to product_documentation is currently handled primarily in catch, so this path can be skipped.
Steps
- On
main, inspectprocessMetadatainbin/generate-readme.mjs. - Note
validateStatus: () => trueon the HEAD request and fallback logic incatch. - Simulate HEAD returning
{ status: 404 }(no throw).
Actual
remoteUrlExists can stay true, so support_documentation may incorrectly remain .../docs/getting-support even when that page is 404.
Expected
When HEAD returns 404, fallback should use product_documentation.
Repro 2: null Link header parse dereference
Why this happens
parse-link-header can return null for malformed/oversized headers.
Current code dereferences link.next without a null guard.
Steps
- On
main, inspectgetReposinbin/generate-readme.mjs. - Simulate
parseLinkHeader(res.headers.link)returningnull. - Run the logic that checks
if (link.next).
Actual
Throws TypeError: Cannot read properties of null (reading 'next').
Expected
If parsing returns null, generation should continue without throwing.
Impact
- Can produce incorrect support links in generated README metadata.
- Can terminate README generation unexpectedly on malformed/oversized Link headers.
Proposed fix
A fix has already been implemented here:
#7305