[GH-ISSUE #199] dust -h panics when stdout is closed #90

Closed
opened 2026-06-08 11:25:37 +03:00 by zhus · 3 comments
Owner

Originally created by @lopopolo on GitHub (Nov 29, 2021).
Original GitHub issue: https://github.com/bootandy/dust/issues/199

$ RUST_BACKTRACE=1 dust -h | false
thread 'main' panicked at 'Error writing Error to stdout: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }', /Users/brew/Library/Caches/Homebrew/cargo_cache/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/errors.rs:401:55
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::result::unwrap_failed
   3: core::result::Result<T,E>::expect
   4: clap::errors::Error::exit
   5: clap::app::App::get_matches_from::{{closure}}
   6: clap::app::App::get_matches
   7: dust::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
$ dust --version
Dust 0.7.5

Clap provides a get_matches_from_safe API that returns a Result rather than panicking when failing to write to stdout.

Here's some MIT-licensed code I use in one of my projects that does this dance in a panic-free way:

https://github.com/artichoke/artichoke/blob/d527412f9438aeba4cadb1f4303237f6f9e0cd4d/src/bin/artichoke.rs#L138-L173

Originally created by @lopopolo on GitHub (Nov 29, 2021). Original GitHub issue: https://github.com/bootandy/dust/issues/199 ```console $ RUST_BACKTRACE=1 dust -h | false thread 'main' panicked at 'Error writing Error to stdout: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }', /Users/brew/Library/Caches/Homebrew/cargo_cache/registry/src/github.com-1ecc6299db9ec823/clap-2.33.3/src/errors.rs:401:55 stack backtrace: 0: _rust_begin_unwind 1: core::panicking::panic_fmt 2: core::result::unwrap_failed 3: core::result::Result<T,E>::expect 4: clap::errors::Error::exit 5: clap::app::App::get_matches_from::{{closure}} 6: clap::app::App::get_matches 7: dust::main note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. $ dust --version Dust 0.7.5 ``` Clap provides a `get_matches_from_safe` API that returns a `Result` rather than panicking when failing to write to stdout. Here's some MIT-licensed code I use in one of my projects that does this dance in a panic-free way: https://github.com/artichoke/artichoke/blob/d527412f9438aeba4cadb1f4303237f6f9e0cd4d/src/bin/artichoke.rs#L138-L173
zhus closed this issue 2026-06-08 11:25:37 +03:00
Author
Owner

@lopopolo commented on GitHub (Nov 29, 2021):

I've opened up this ticket with upstream clap to see if the maintainers are open to fixing this panic on the v2 branch:

<!-- gh-comment-id:981203290 --> @lopopolo commented on GitHub (Nov 29, 2021): I've opened up this ticket with upstream clap to see if the maintainers are open to fixing this panic on the v2 branch: - https://github.com/clap-rs/clap/discussions/3055
Author
Owner

@bootandy commented on GitHub (Dec 3, 2021):

From that thread:
v2.33.4 has been released that fixes this panic

<!-- gh-comment-id:985331714 --> @bootandy commented on GitHub (Dec 3, 2021): From that thread: v2.33.4 has been released that fixes this panic
Author
Owner

@bootandy commented on GitHub (Feb 26, 2022):

I have moved to Clap 3, this should solve this.

<!-- gh-comment-id:1052043196 --> @bootandy commented on GitHub (Feb 26, 2022): I have moved to Clap 3, this should solve this.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: bootandy/archived-dust#90