{"record":{"id":"8b36c103de9bef87","repo":"uutils/coreutils","slug":"invalid-value","errorCode":null,"errorMessage":"invalid value","messagePattern":"invalid value","errorType":"validation","errorClass":"clap::Error","httpStatus":null,"severity":"error","filePath":"src/uucore/src/lib/features/parser/shortcut_value_parser.rs","lineNumber":38,"sourceCode":"/// `ShortcutValueParser` is similar to clap's `PossibleValuesParser`: it verifies that the value is\n/// from an enumerated set of `PossibleValue`.\n///\n/// Whereas `PossibleValuesParser` only accepts exact matches, `ShortcutValueParser` also accepts\n/// shortcuts as long as they are unambiguous.\nimpl ShortcutValueParser {\n    /// Create a new `ShortcutValueParser` from a list of `PossibleValue`.\n    pub fn new(values: impl Into<Self>) -> Self {\n        values.into()\n    }\n\n    fn generate_clap_error(\n        &self,\n        cmd: &clap::Command,\n        arg: Option<&clap::Arg>,\n        value: &str,\n        possible_values: &[&PossibleValue],\n    ) -> clap::Error {\n        let mut err = clap::Error::new(ErrorKind::InvalidValue).with_cmd(cmd);\n\n        if let Some(arg) = arg {\n            err.insert(\n                ContextKind::InvalidArg,\n                ContextValue::String(arg.to_string()),\n            );\n        }\n\n        err.insert(\n            ContextKind::InvalidValue,\n            ContextValue::String(value.to_string()),\n        );\n\n        err.insert(\n            ContextKind::ValidValue,\n            ContextValue::Strings(self.0.iter().map(|x| x.get_name().to_string()).collect()),\n        );\n","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/uutils/coreutils/blob/92995feca29e324a7c559ede91db81c32d9f5d59/src/uucore/src/lib/features/parser/shortcut_value_parser.rs#L20-L56","documentation":"The ShortcutValueParser builds a clap InvalidValue error when a user-supplied value does not match any possible value (or matches ambiguously). generate_clap_error assembles the clap::Error with the offending arg and value context for a helpful CLI message.","triggerScenarios":"Calling parse_ref (or clap value parsing) with a value string that matches none of the parser's PossibleValue entries, e.g. an unknown enum-like CLI option value.","commonSituations":"Typos in CLI option values; scripts passing wrong-case values; versions where a value was renamed.","solutions":["Use one of the parser's accepted values (check --help output)","Rely on the possible-value suggestions shown in the clap error message","Add the needed value to the PossibleValue list if you own the utility"],"exampleFix":"// before\nparse_ref(cmd, &arg, OsStr::new(\"recursve\"))\n// after\nparse_ref(cmd, &arg, OsStr::new(\"recursive\"))","handlingStrategy":"validation","validationCode":"let allowed = [\"recursive\", \"files0-from\", \"...\"]; // see --help\nassert!(allowed.contains(&user_value), \"unsupported value: {user_value}\");","typeGuard":null,"tryCatchPattern":"match ShortcutValueParser::parse_ref(cmd, arg, value) {\n    Err(e) if e.kind() == clap::error::ErrorKind::InvalidValue => {\n        eprintln!(\"invalid value {value:?}; see --help\");\n    }\n    r => r?,\n}","preventionTips":["Validate CLI values against --help before invoking programmatically","Keep value casing consistent with the accepted possible values","Update scripts when a utility renames an option value"],"tags":["cli","clap","parsing","invalid-value"],"backgroundTag":"invalid-cli-argument","analyzedSha":"92995feca29e324a7c559ede91db81c32d9f5d59","analyzedAt":"2026-09-20T12:39:35.476Z","contentChangedAt":"2026-09-20T12:39:35.476Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}