{"id":"dd2fd85514692b21","repo":"rust-lang/cargo","slug":"argument-for-color-must-be-auto-always-or-neve","errorCode":null,"errorMessage":"argument for --color must be auto, always, or never, but found `{}`","messagePattern":"argument for --color must be auto, always, or never, but found `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cargo-util-terminal/src/shell.rs","lineNumber":593,"sourceCode":"    fn to_anstream_color_choice(self) -> anstream::ColorChoice {\n        match self {\n            ColorChoice::Always => anstream::ColorChoice::Always,\n            ColorChoice::Never => anstream::ColorChoice::Never,\n            ColorChoice::CargoAuto => anstream::ColorChoice::Auto,\n        }\n    }\n}\n\nimpl std::str::FromStr for ColorChoice {\n    type Err = anyhow::Error;\n    fn from_str(color: &str) -> Result<Self, Self::Err> {\n        let cfg = match color {\n            \"always\" => ColorChoice::Always,\n            \"never\" => ColorChoice::Never,\n\n            \"auto\" => ColorChoice::CargoAuto,\n\n            arg => anyhow::bail!(\n                \"argument for --color must be auto, always, or \\\n                     never, but found `{}`\",\n                arg\n            ),\n        };\n        Ok(cfg)\n    }\n}\n\nfn supports_color(choice: anstream::ColorChoice) -> bool {\n    match choice {\n        anstream::ColorChoice::Always\n        | anstream::ColorChoice::AlwaysAnsi\n        | anstream::ColorChoice::Auto => true,\n        anstream::ColorChoice::Never => false,\n    }\n}\n","sourceCodeStart":575,"sourceCodeEnd":611,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/crates/cargo-util-terminal/src/shell.rs#L575-L611","documentation":"From ColorChoice::from_str (crates/cargo-util-terminal/src/shell.rs:584-600), the FromStr impl that parses Cargo's global --color option. Only the case-sensitive lowercase strings `always`, `never`, and `auto` map to a variant; everything else bails with this anyhow error, which clap surfaces as an invalid-value error. The three variants map to anstream::ColorChoice (Always / Never / CargoAuto).","triggerScenarios":"Running any cargo command with `--color yes`, `--color=on`, `--color TRUE`, `--color 1`, or a misspelled value. Also triggered programmatically by calling ColorChoice::from_str(\"on\") from code embedding cargo-util-terminal.","commonSituations":"Scripts, makefiles, or CI configs that set --color=on (valid in many GNU tools but not Cargo). Muscle memory from `grep --color=always`. A typo like `--colour=auto`. Aliases piping Cargo output through tools that expect yes/no.","solutions":["Use exactly one of: `auto`, `always`, or `never` (lowercase).","Omit the flag entirely; Cargo defaults to auto.","If driving Cargo from a wrapper, map your boolean to one of the three accepted strings before passing it."],"exampleFix":"// before\ncargo build --color=on\n\n// after\ncargo build --color=always","handlingStrategy":"validation","validationCode":"// Validate a --color value before it reaches ColorChoice::from_str\nfn valid_color_choice(s: &str) -> bool {\n    matches!(s, \"always\" | \"never\" | \"auto\")\n}\n\nlet color = if valid_color_choice(raw) { raw } else { \"auto\" };","typeGuard":"fn is_valid_color_choice(s: &str) -> bool {\n    matches!(s, \"always\" | \"never\" | \"auto\")\n}","tryCatchPattern":"// Parse defensively if you must take arbitrary input\nuse cargo_util_terminal::ColorChoice;\nuse std::str::FromStr;\nlet choice = match ColorChoice::from_str(raw) {\n    Ok(c) => c,\n    Err(_) => ColorChoice::CargoAuto, // fall back to auto\n};","preventionTips":["Standardize on auto/always/never in all wrappers and CI configs.","Centralize color-flag construction in one helper rather than copying strings."],"tags":["cargo","cli","color","argument-parsing","cargo-util-terminal"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}