rust-lang/cargo · error

argument for --color must be auto, always, or never, but fou

Error message

argument for --color must be auto, always, or never, but found `{}`

What it means

xtask-spellcheck wraps the `typos` CLI and forwards a --color argument. It validates that the value is exactly 'auto', 'always', or 'never'; any other value bails with the standard Cargo color-argument message. This duplicates ColorChoice::from_str's contract at the spellcheck entrypoint.

Source

Thrown at crates/xtask-spellcheck/src/main.rs:69

            Arg::new("write-changes")
                .long("write-changes")
                .short('w')
                .help("Write fixes out")
                .action(ArgAction::SetTrue)
                .global(true),
        )
}

pub fn exec(matches: &clap::ArgMatches) -> Result<()> {
    let mut args = vec![];

    match matches.get_one::<String>("color") {
        Some(c) if matches!(c.as_str(), "auto" | "always" | "never") => {
            args.push("--color");
            args.push(c);
        }
        Some(c) => {
            anyhow::bail!(
                "argument for --color must be auto, always, or \
                 never, but found `{}`",
                c
            );
        }
        _ => {}
    }

    if matches.get_flag("quiet") {
        args.push("--quiet");
    }

    let verbose_count = matches.get_count("verbose");

    for _ in 0..verbose_count {
        args.push("--verbose");
    }
    if matches.get_flag("write-changes") {

View on GitHub (pinned to eb98b54bc9)

Solutions

  1. Use one of: auto, always, never.
  2. Normalize user input in your wrapper to these exact strings.
  3. Drop the flag entirely to rely on auto-detection.

Example fix

// before
cargo spellcheck --color yes
// after
cargo spellcheck --color always
Defensive patterns

Strategy: validation

Validate before calling

fn valid_color(s: &str) -> bool {
    matches!(s, "auto" | "always" | "never")
}
if let Some(c) = color_arg {
    if !valid_color(c) { eprintln!("--color must be auto|always|never"); }
}

Type guard

null

Try / catch

null

Prevention

When it happens

Trigger: Running `cargo spellcheck --color yes` (or 'on'/'force'/'true') — the value fails the match against the three accepted strings.

Common situations: Aliases or wrapper scripts passing boolean-style color values; copy-pasted flags from other tools that accept 'yes'/'on'.

Related errors


AI-assisted analysis of rust-lang/cargo@eb98b54bc9 (2026-08-11). Data as JSON: /api/errors/3900f4ccb7e75e48. Report an issue: GitHub.