Skip to content

Exit quietly when the reader closes stdout - #16

Merged
openai0229 merged 1 commit into
mainfrom
fix/broken-pipe
Sep 20, 2026
Merged

openai0229 merged 1 commit into
mainfrom
fix/broken-pipe

Conversation

@openai0229

Copy link
Copy Markdown
Contributor

What

sqlx sql execute … | head -c 100 panicked with thread 'main' panicked at …/stdio.rs:1165: failed printing to stdout: Broken pipe on stderr and exit code 101, because the result and error paths print with println!, which panics when the write fails.

Both paths now go through one helper: BrokenPipe exits silently with status 0 (the consumer stopped reading, which is normal for head), any other write failure still reports itself on stderr and exits 1. The streamed event output already used fallible writes.

Verification

Large Oracle result (5000 rows), stdout piped to head -c 100:

published 0.1.6:  1 panic line on stderr
this branch:      0 lines on stderr, no panic
  • Complete output is unaffected: SELECT COUNT(*) … level <= 5000 returns [['5000']].
  • Successful commands and the existing tests are unchanged; cargo fmt, clippy --workspace --all-targets --locked -- -D warnings and cargo test -p ottermind-sqlx pass.

Risks and limits

  • A closed pipe now exits 0; scripts that rely on a non-zero status from a truncated read must check output completeness themselves.
  • Only stdout is handled; stderr write failures keep the default behaviour.

@openai0229
openai0229 merged commit cfb7cdd into main Sep 20, 2026
9 checks passed
@openai0229
openai0229 deleted the fix/broken-pipe branch September 20, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant