Skip to content

bin/generate-readme.mjs: 404 support-doc fallback is skipped and Link header parse can throw #7354

@akgitrepos

Description

@akgitrepos

Summary

bin/generate-readme.mjs has two edge-case bugs on main:

  1. Support docs fallback is skipped when HEAD returns HTTP 404.
  2. README generation can throw when parse-link-header returns null.

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: main at a0e6fcbf05292d3fa60c8090295365b1180656bc

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

  1. On main, inspect processMetadata in bin/generate-readme.mjs.
  2. Note validateStatus: () => true on the HEAD request and fallback logic in catch.
  3. 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

  1. On main, inspect getRepos in bin/generate-readme.mjs.
  2. Simulate parseLinkHeader(res.headers.link) returning null.
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs more infoThis issue needs more information from the customer to proceed.type: processA process-related concern. May include testing, release, or the like.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions