{"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/92995feca29e324a7c559ede91db81c32d9f5d59/src/uu/realpath/src/realpath.rs#L36-L72","documentation":"realpath rejects an empty string operand at argument-parse time via a custom clap ValueValidation error carrying the localized 'realpath-invalid-empty-operand' message. POSIX realpath requires a non-empty path operand, so passing '' (e.g. from an unquoted empty variable) is invalid input rather than a filesystem error.","triggerScenarios":"Invoking `realpath \"\"` directly, or `realpath \"$VAR\"` where VAR is unset/empty; scripting patterns like `realpath \"$1\"` when the positional argument is missing; --relative-to/-- combinations fed an empty value through the custom value parser (parse_ref).","commonSituations":"Shell scripts where a variable was never set (missing config/env); functions taking a path parameter called without arguments; pipelines producing empty output consumed as a path argument.","solutions":["Quote and validate variables before use: ensure the path argument is non-empty before calling realpath.","Provide a default path in scripts: realpath \"${1:?path required}\".","Fix the upstream producer that emits an empty value (missing env var, failed command substitution).","Use `${VAR:?}` or `: \"${VAR:?}\"` guards to fail early with a clear message."],"exampleFix":"#!/bin/sh\n# before: realpath \"$TARGET\" -> error when TARGET empty\n# after: fail early with a clear message\n: \"${TARGET:?TARGET must be set to a non-empty path}\"\nrealpath \"$TARGET\"","handlingStrategy":"validation","validationCode":"#!/bin/sh\n: \"${TARGET:?TARGET must be a non-empty path}\"\n[ -n \"$TARGET\" ] || { echo \"empty path\" >&2; exit 1; }\nrealpath \"$TARGET\"","typeGuard":"function isValidPathOperand(v) {\n  return typeof v === 'string' && v.length > 0;\n}","tryCatchPattern":"const { status, stderr } = spawnSync('realpath', [target]);\nif (status !== 0 && /empty/i.test(stderr.toString())) {\n  console.error('realpath: empty operand — check the variable feeding the argument');\n}","preventionTips":["Always quote and default-check variables used as path operands (${VAR:?})","Validate function parameters before spawning realpath","Beware command substitution failures producing empty strings","Fail fast on missing positional args instead of passing them through"],"tags":["realpath","cli","empty-argument","validation"],"backgroundTag":"empty-required-field","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"}