Skip to content

volta -h panics when stdout is closed #1055

@lopopolo

Description

@lopopolo
$ volta --version
Updating your Volta directory. This may take a few moments...
1.0.5
$ RUST_BACKTRACE=1 volta -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.0/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: volta::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions