uutils/coreutils · error · clap::Error
realpath-invalid-empty-operand
Error message
realpath-invalid-empty-operand
What it means
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.
Source
Thrown at src/uu/realpath/src/realpath.rs:54
const OPT_RELATIVE_BASE: &str = "relative-base";
const ARG_FILES: &str = "files";
/// Custom parser that validates `OsString` is not empty
#[derive(Clone, Debug)]
struct NonEmptyOsStringParser;
impl TypedValueParser for NonEmptyOsStringParser {
type Value = OsString;
fn parse_ref(
&self,
_cmd: &Command,
_arg: Option<&Arg>,
value: &OsStr,
) -> Result<Self::Value, clap::Error> {
if value.is_empty() {
let mut err = clap::Error::new(clap::error::ErrorKind::ValueValidation);
err.insert(
clap::error::ContextKind::Custom,
clap::error::ContextValue::String(translate!("realpath-invalid-empty-operand")),
);
return Err(err);
}
Ok(value.to_os_string())
}
}
impl ValueParserFactory for NonEmptyOsStringParser {
type Parser = Self;
fn value_parser() -> Self::Parser {
Self
}
}
View on GitHub (pinned to 85295bbf78)
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
Example fix
// before
let dir = env::var("TARGET_DIR").unwrap_or_default();
// after
let dir = env::var("TARGET_DIR").expect("TARGET_DIR must be set to a non-empty path"); Defensive patterns
Strategy: validation
Validate before calling
if operand.is_empty() {
eprintln!("realpath: invalid operand: empty string");
std::process::exit(1);
}
realpath(operand)?; Type guard
fn is_valid_operand(s: &OsStr) -> bool { !s.is_empty() } Try / catch
match result {
Err(e) if e.to_string().contains("realpath-invalid-empty-operand") => default_path(),
other => other?,
} Prevention
- Use ${var:?msg} for required path variables in shell
- Quote and default-expand path arguments
- Filter empty strings from argument arrays before spawning
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- InvalidValue clap error for unmatched argument value
- InvalidUtf8 clap error for non-UTF-8 argument value
AI-assisted analysis of uutils/coreutils@85295bbf78 (2026-08-31).
Data as JSON: /api/errors/fc505aa82d23182c.
Report an issue: GitHub.