Skip to content

cargo --help panics when stdout is closed #10131

@lopopolo

Description

@lopopolo

Problem

cargo --help panics when stdout is closed.

There is a discussion about this API papercut upstream: clap-rs/clap#3055.

Steps

$ RUST_BACKTRACE=1 cargo --help | false
thread 'main' panicked at 'Error writing Error to stdout: Os { code: 32, kind: BrokenPipe, message: "Broken pipe" }', /Users/runner/.cargo/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: cargo::exit_with_error
   6: cargo::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

Possible Solution(s)

Use the App::get_matches_from_safe API and manually handle the error it returns, suppressing failures to write to either stdout or stderr.

Notes

No response

Version

cargo 1.56.0 (4ed5d137b 2021-10-04)
release: 1.56.0
commit-hash: 4ed5d137baff5eccf1bae5a7b2ae4b57efad4a7d
commit-date: 2021-10-04

Activity

weihanglo

weihanglo commented on Dec 4, 2021

@weihanglo
Member

I saw it fixed on clap v2.33.4. Really great!
clap-rs/clap@accf3d2

ehuss

ehuss commented on Dec 4, 2021

@ehuss
Contributor

Thanks @weihanglo, would you mind posting a PR that updates our Cargo.toml to "2.34.0"?

added a commit that references this issue on Dec 4, 2021
0507d9f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @ehuss@lopopolo@weihanglo

      Issue actions

        `cargo --help` panics when stdout is closed · Issue #10131 · rust-lang/cargo