{"record":{"id":"fc505aa82d23182c","repo":"uutils/coreutils","slug":"realpath-invalid-empty-operand","errorCode":null,"errorMessage":"realpath-invalid-empty-operand","messagePattern":"realpath-invalid-empty-operand","errorType":"validation","errorClass":"clap::Error","httpStatus":null,"severity":"error","filePath":"src/uu/realpath/src/realpath.rs","lineNumber":54,"sourceCode":"const OPT_RELATIVE_BASE: &str = \"relative-base\";\n\nconst ARG_FILES: &str = \"files\";\n\n/// Custom parser that validates `OsString` is not empty\n#[derive(Clone, Debug)]\nstruct NonEmptyOsStringParser;\n\nimpl TypedValueParser for NonEmptyOsStringParser {\n    type Value = OsString;\n\n    fn parse_ref(\n        &self,\n        _cmd: &Command,\n        _arg: Option<&Arg>,\n        value: &OsStr,\n    ) -> Result<Self::Value, clap::Error> {\n        if value.is_empty() {\n            let mut err = clap::Error::new(clap::error::ErrorKind::ValueValidation);\n            err.insert(\n                clap::error::ContextKind::Custom,\n                clap::error::ContextValue::String(translate!(\"realpath-invalid-empty-operand\")),\n            );\n            return Err(err);\n        }\n        Ok(value.to_os_string())\n    }\n}\n\nimpl ValueParserFactory for NonEmptyOsStringParser {\n    type Parser = Self;\n\n    fn value_parser() -> Self::Parser {\n        Self\n    }\n}\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/uutils/coreutils/blob/85295bbf788bfd7a6926ba692031563504b304b7/src/uu/realpath/src/realpath.rs#L36-L72","documentation":"realpath rejects an empty operand at argument-parsing time. The custom clap value parser (`parse_ref`) checks `value.is_empty()` and raises a ValueValidation error carrying the localized message \"realpath-invalid-empty-operand\", because realpath has no meaningful answer for an empty path.","triggerScenarios":"Running `realpath ''` or otherwise passing an empty string as a path argument (e.g. from an unset shell variable, `$FOO` that expands to nothing, or a script that builds a path list containing a blank entry).","commonSituations":"Unquoted/unset environment variables in shell scripts (`realpath \"$dir\"` with `dir=`), pipeline output that yields blank lines, or programmatic invocation of the utility with empty argv entries.","solutions":["Pass a real path operand to realpath","In shell scripts, default or check the variable first: `${dir:?dir is empty}`","Filter empty entries from path lists before invoking realpath"],"exampleFix":"// before\nlet dir = env::var(\"TARGET_DIR\").unwrap_or_default();\n// after\nlet dir = env::var(\"TARGET_DIR\").expect(\"TARGET_DIR must be set to a non-empty path\");","handlingStrategy":"validation","validationCode":"if operand.is_empty() {\n    eprintln!(\"realpath: invalid operand: empty string\");\n    std::process::exit(1);\n}\nrealpath(operand)?;","typeGuard":"fn is_valid_operand(s: &OsStr) -> bool { !s.is_empty() }","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"realpath-invalid-empty-operand\") => default_path(),\n    other => other?,\n}","preventionTips":["Use ${var:?msg} for required path variables in shell","Quote and default-expand path arguments","Filter empty strings from argument arrays before spawning"],"tags":["clap","argument-parsing","realpath"],"backgroundTag":"empty-path-argument","analyzedSha":"85295bbf788bfd7a6926ba692031563504b304b7","analyzedAt":"2026-08-31T11:11:36.175Z","contentChangedAt":"2026-08-31T11:11:36.175Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}