Skip to content

fix(console): surface stdout write failures with GNU exit mapping (#1368) - #1419

Merged
caomengxuan666 merged 1 commit into
mainfrom
fix/iss-stdout-write-errors
Oct 27, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
fix/iss-stdout-write-errors

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #1368.

The shared console layer (src/utils/console.cppm) now records the first failed stdout write and exposes report_stdout_write_error(prog, fatal_status); the issue's named commands consult it on their exit paths:

Probe Before After
seq 3 >&- exit 0, silent seq: write error: Bad file descriptor, rc1
printf 'hi\n' >&- exit 0, silent write error, rc1
grep x f >&- exit 0, silent rc2
ls >&- exit 0, silent rc2
find . -print >&- exit 0, silent rc1
tac f >&- exit 0, silent rc1
cat f >&- exit 0, silent cat: write error, rc1

Broken-pipe failures keep their quiet SIGPIPE-style death, and the write-error state stops the producer early — seq 5000000 | head -1 no longer formats the whole stream. stderr writes (safeErrorPrint) are unaffected; console (WriteConsoleW) paths are untouched.

Tests: per-command regression pins landed in the seq/cat/grep/ls/printf/tac/find/tty unit tests (closed-stdout and broken-pipe fixtures). Full suite: 3349 passed, 0 failed (baseline xargs CONIN$ / issue_1288 / find.issue_1309 exclusions).

i18n delta: new diagnostic strings ("write error: Bad file descriptor" family) are composed at runtime from the program name + strerror text; no catalog keys added or removed (extract byte-identical).

)

The shared console layer now records the first failed stdout write
(broken pipe vs other errors) and exposes a report_stdout_write_error()
query. seq, cat, printf, grep, ls, find, tac and tty consult it on their
exit paths: a closed stdout (>&-) now reports "<prog>: write error: Bad
file descriptor" with the tool's GNU exit status, and a broken pipe
stops the producer early (seq N | head -1 no longer formats the whole
stream). Per-command exit mapping follows GNU: cat/printf/seq/tac report
the write error, grep/ls exit 2, find exits 1.
@caomengxuan666
caomengxuan666 merged commit ea8e40c into main Oct 27, 2026
7 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/iss-stdout-write-errors branch October 27, 2026 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant