#5579·clap

Duplicated "error:" prefix

Author: d-e-s-oCreated Jul 10, 2024Updated Aug 23, 2026
LabelsC-bug

Please complete the following tasks

Rust Version

rustc 1.79.0-nightly (129f3b996 2024-06-10) (gentoo)

Clap Version

4.5.4

Minimal reproducible code

rust
use std::env::args_os;
use anyhow::Result;
use clap::Parser;

/// Simple program to greet a person
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
    /// Name of the person to greet
    #[arg(short, long)]
    name: String,
}

fn main() -> Result<()> {
    let _args = Args::try_parse_from(args_os())?;
    Ok(())
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=6221486eaf814c633157f1c9fdf27c12

Steps to reproduce the bug with the above code

cargo run

Actual Behaviour

Prints:

Error: error: the following required arguments were not provided:
  --name <NAME>

Usage: playground --name <NAME>

For more information, try '--help'.

Expected Behaviour

Prints:

Error: the following required arguments were not provided:
  --name <NAME>

Usage: playground --name <NAME>

For more information, try '--help'.

Additional Context

The "error:" prefix is duplicated. I find this behavior irritating. One prefix seems to be added by the standard library, the other by clap (I don't believe clap is alone with such behavior)

In my opinion the standard library's behavior is questionable -- it's just way too opinionated and this is a good example -- but I wanted to get your guys' take and have an issue to reference to make the case for changing it (which I suppose may be a hard sell irrespectively).

In general, though, it also feels as if just the typical wording of "failed to [...]" or similar would be sufficient for convey the issue. Meaning that there is no need for an "error:" at all, even from the clap side. It just depends too much on the context how the error is reported whether it makes sense to include such a prefix or not.

Any opinions/comments/thoughts?

Debug Output

No response