Skip to content

fix(completions): exit cleanly when the output pipe closes - #726

Merged
dubadub merged 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/708-completions-broken-pipe
Oct 14, 2026
Merged

dubadub merged 1 commit into
cooklang:mainfrom
drawmeanelephant:fix/708-completions-broken-pipe

Conversation

@drawmeanelephant

Copy link
Copy Markdown
Contributor

Closes #708

clap_complete::generate unwraps its writes internally, so cook completions bash | head -1 panicked with a BrokenPipe (exit 101). Now generates into a buffer and treats ErrorKind::BrokenPipe on the final write_all as a clean exit — the standard behaviour for a CLI whose reader went away.

Test plan

  • cook completions bash | head -1 exits 0 (verified 3/3 runs, previously 101 8/8)
  • cook completions zsh still prints a full script to stdout

`clap_complete::generate` unwraps its writes internally, so
`cook completions bash | head -1` panicked with BrokenPipe (exit 101).
Generate into a buffer and write it to stdout, treating a broken pipe
as done — the standard behaviour for a CLI whose reader went away.

Closes #708
@drawmeanelephant
drawmeanelephant force-pushed the fix/708-completions-broken-pipe branch from e475199 to aedc970 Compare October 13, 2026 14:33

@LeMyst LeMyst left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Generating into a Vec can't fail, so clap_complete's internal expect can't fire. The write_all to stdout then maps BrokenPipe to Ok, and since Rust ignores SIGPIPE the error does arrive as BrokenPipe.


🤖 Analysis and recommendations made by Claude (Anthropic's AI assistant), posted on behalf of @LeMyst.

@dubadub
dubadub merged commit 4c42a15 into cooklang:main Oct 14, 2026
6 checks passed
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.

cook completions panics with BrokenPipe when piped to head

3 participants