{"record":{"id":"13fe30bb2b9881d5","repo":"cross-rs/cross","slug":"argument-for-color-must-be-auto-always-or-never-but-found","errorCode":null,"errorMessage":"argument for --color must be auto, always, or never, but found `{arg}`","messagePattern":"argument for --color must be auto, always, or never, but found `(.+?)`","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/shell.rs","lineNumber":127,"sourceCode":"#[derive(Debug, Clone, Copy, PartialEq, Eq)]\npub enum ColorChoice {\n    /// force color output\n    Always,\n    /// force disable color output\n    Never,\n    /// intelligently guess whether to use color output\n    Auto,\n}\n\nimpl FromStr for ColorChoice {\n    type Err = eyre::ErrReport;\n\n    fn from_str(s: &str) -> Result<ColorChoice> {\n        match s {\n            \"always\" => Ok(ColorChoice::Always),\n            \"never\" => Ok(ColorChoice::Never),\n            \"auto\" => Ok(ColorChoice::Auto),\n            arg => eyre::bail!(\n                \"argument for --color must be auto, always, or never, but found `{arg}`\"\n            ),\n        }\n    }\n}\n\n// Should simplify the APIs a lot.\n#[derive(Debug, Clone, PartialEq, Eq)]\npub struct MessageInfo {\n    pub color_choice: ColorChoice,\n    pub verbosity: Verbosity,\n    pub stdout_needs_erase: bool,\n    pub stderr_needs_erase: bool,\n    pub cross_debug: bool,\n    pub has_warned: bool,\n}\n\nimpl MessageInfo {","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/cross-rs/cross/blob/8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27/src/shell.rs#L109-L145","documentation":"This error is thrown by ColorChoice::from_str when the value passed for --color is not exactly 'auto', 'always', or 'never'. It is a strict CLI argument validation: any other spelling (including abbreviations or casing variants) is rejected.","triggerScenarios":"from_str is invoked during CLI argument parsing (clap-style) with a --color value that does not match one of the three accepted literals in the match arms.","commonSituations":"Typos like 'alway' or 'Always'; passing 'true'/'false' or 'ansi'; scripts interpolating an empty or malformed value into --color; users copying a flag value from a different tool that accepts more choices.","solutions":["Re-run with exactly one of: --color auto, --color always, or --color never","Check the script or alias producing the value for typos or casing differences","Remove the --color flag entirely to use the default (auto) behavior"],"exampleFix":"// before\nmytool --color Always\n// after\nmytool --color always","handlingStrategy":"validation","validationCode":"fn is_valid_color_choice(s: &str) -> bool {\n    matches!(s, \"auto\" | \"always\" | \"never\")\n}\n// validate argv value before invoking the CLI\nif !is_valid_color_choice(&color_value) { eprintln!(\"--color must be auto, always, or never\"); std::process::exit(2); }","typeGuard":"fn as_color_choice(s: &str) -> Option<ColorChoice> {\n    match s {\n        \"always\" => Some(ColorChoice::Always),\n        \"never\" => Some(ColorChoice::Never),\n        \"auto\" => Some(ColorChoice::Auto),\n        _ => None,\n    }\n}","tryCatchPattern":"match color_value.parse::<ColorChoice>() {\n    Ok(c) => apply(c),\n    Err(_) => {\n        eprintln!(\"--color must be auto, always, or never\");\n        std::process::exit(2);\n    }\n}","preventionTips":["Use an enum-backed CLI parser (ValueEnum) so invalid values are rejected with help text","Normalize/trim user input before passing --color","Document the three accepted values in --help","Add a clap possible_values list so shell completion offers valid choices"],"tags":["cli","color","argument-parsing"],"backgroundTag":"invalid-cli-argument","analyzedSha":"8c1a8aa4b661711f4b7b6ac07c2e8929ce2f7d27","analyzedAt":"2026-09-13T15:10:43.988Z","contentChangedAt":"2026-09-13T15:10:43.988Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}