{"record":{"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/eb98b54bc9f3c74519f43d066cb3fd02ebc88df0/crates/cargo-util-terminal/src/shell.rs#L575-L611","documentation":"ColorChoice::from_str parses the --color CLI argument and only accepts 'always', 'never', or 'auto'. Any other string is rejected with a bail! describing the valid choices. This is the canonical color-option validator shared across Cargo's shells.","triggerScenarios":"Passing `--color yes`, `--color true`, `--color=1`, or any non-recognized value to a Cargo (or cargo-util-terminal based) command that forwards to this FromStr impl.","commonSituations":"Scripts/aliases that pass 'yes'/'on'/'force' instead of 'always'; CI config typos; tooling that assumes boolean-style values.","solutions":["Use exactly one of: auto, always, never.","If accepting user input, validate/normalize to the three accepted values before forwarding to Cargo.","Map boolean input (true->always, false->never) in your wrapper."],"exampleFix":"// before\ncargo build --color yes\n// after\ncargo build --color always","handlingStrategy":"validation","validationCode":"fn valid_color(s: &str) -> bool {\n    matches!(s, \"auto\" | \"always\" | \"never\")\n}\n// before forwarding:\nif !valid_color(&val) {\n    eprintln!(\"--color must be auto|always|never\");\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Constrain color option input with an enum/clap value_parser.","Normalize boolean inputs to always/never in wrappers."],"tags":["cargo","cli","color","argument-validation"],"backgroundTag":null,"analyzedSha":"eb98b54bc9f3c74519f43d066cb3fd02ebc88df0","analyzedAt":"2026-08-11T17:42:36.556Z","contentChangedAt":"2026-08-11T17:42:36.556Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}