InditexTech / InditexTech/docouture

check-links.mjs: process.exit(1) truncates stdout, hiding which links are actually broken

Open Beginner friendly
#231 0 comments 0 reactions 0 assignees View on GitHub
kind/bug
Dominant language
JavaScript
Stars
1
Forks
0
Avg merge
3h 53m
Merged PRs (30d)
93

Description

## What's broken

`check-links.mjs` (both the CLI's scaffolded template and docouture's own docs copy) calls `process.exit(1)` immediately after a burst of `console.log` calls listing the broken external links:

```js
if (external.length > 0) {
for (const link of external) {
console.log(`::error::broken external link: ${link.url} (parent: ${link.parent ?? 'unknown'})`)
}
console.error(`\n${external.length} broken external link(s) found.`)
process.exit(1)
}
```

`process.exit()` terminates the process immediately. When stdout is a pipe — which it is in CI (GitHub Actions captures step output through a pipe, not a TTY) — Node's writes to it are asynchronous. A tight loop of `console.log` calls followed immediately by `process.exit()` can get truncated: the process dies before the OS drains the pending write queue. `console.error` (stderr) seems to survive more reliably, so the tally line prints but the individual broken-link lines above it don't.

## Where I saw it

`InditexTech/weavejs`, `docouture-publish` run [34347631041 / job 102452926606](https://github.com/InditexTech/weavejs/actions/runs/34347631041/job/102452926606). The step failed, log says:

```
6 broken external link(s) found.
Process completed with exit code 1.
```

...but there isn't a single `broken external link:` line anywhere in the raw log (checked via both the job-logs API and the run's log zip, 1598 lines, none matching). Meanwhile the *other* two warning loops in the same script (`local` and `non-representative`, hundreds of lines combined) printed in full just before it — consistent with truncation hitting only the last, small write right before `process.exit()`, not general output loss.

Net effect: the check correctly fails the build, but the one piece of information an author actually needs to fix it — *which* links are broken — never reaches the log.

## Affected files

- `code/packages/cli/templates/starter/scripts/check-links.mjs` (the scaffolded template every `docouture new` site gets)
- `docs/scripts/check-links.mjs` (docouture's own docs site, scaffolded from the same template)

Both have the identical `process.exit(1)` call at the same spot.

## Suggested fix

Replace `process.exit(1)` with `process.exitCode = 1` and let the module finish naturally instead of force-killing the process. `exitCode` sets the process's exit status without an abrupt kill, so Node's own event loop gets to flush pending stdout writes before the process actually exits — same end result (non-zero exit, CI step fails) without the truncation risk.

Already applied as a one-line fix downstream in `InditexTech/weavejs`'s scaffolded copy; happy to open a PR here with the same change to both files if useful.

Contributor guide

Open the contributing guide

Research direction

Compare code/packages/cli/templates/starter/scripts/check-links.mjs with docs/scripts/check-links.mjs, then run the link checker with broken external links to observe the output. Replace the abrupt exit behavior in both copies so every broken-link line reaches the log while the process still finishes with a non-zero status.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
1/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
90/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.