Conversation
On Windows there is no SIGPIPE; when the consumer of `eza`'s output exits before eza writes (e.g. `eza --help | rg` where rg errors out immediately), writes to stdout fail with ERROR_NO_DATA (232) or ERROR_BROKEN_PIPE (109). `get_matches()` delegates help/version and argument-error output to clap's `Error::exit()`, which prints via `print!()`/`println!()` and panics with "failed printing to stdout" when the write fails. Use `try_get_matches()` instead and render the message ourselves, ignoring write failures while still honouring the proper exit code and stderr/stdout split. Fixes the panic reported downstream in BurntSushi/ripgrep#3372.
The v0.23.5 bump commit updated most snapshot files but missed these two --version/-v ptests, leaving trycmd red on main.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On Windows, there is no SIGPIPE. When the process consuming
eza'soutput exits before eza writes — e.g.
eza --help | rgwherergerrors out immediately and closes the read end — writes to stdout fail
with
ERROR_NO_DATA(232) /ERROR_BROKEN_PIPE(109).get_matches()sends--help/--versionoutput and argument errorsthrough clap's
Error::exit(), which prints viaprint!()/println!()— and those macros panic withfailed printing to stdoutwhen the write fails. This is the panicreported downstream in BurntSushi/ripgrep#3372:
Fix
Parse with
try_get_matches()and render help/version/parse errorsourselves:
Error::use_stderr()) and the originalexit code (
Error::exit_code()) are preserved, so--helpstillexits 0 and argument errors still exit with clap's code.
No behaviour change on Unix (SIGPIPE semantics are untouched) or when
stdout is a normal file/terminal.
Testing
cargo check,cargo fmt --checkclean.--help→ 0, invalid args → clap errorcode, both on Linux and Windows builds.
eza --help | <early-exit consumer>no longer panics inthe clap output path; the write failure is swallowed and the process
exits with the expected code.
Note: reproducing the exact panic locally is timing-dependent (a short
single write can slip through before the reader closes), but the panic
site is eliminated structurally rather than worked around.