can1357/oh-my-pi · error · StatError

using '-' to denote standard input does not work in file sys

Error message

using '-' to denote standard input does not work in file system mode

What it means

This error (crates/pi-builtins/src/stat.rs, StdinFilesystemMode) is thrown when the user supplies '-' (standard input) as the operand while running stat in file-system mode. Stat file-system mode needs an actual filesystem path to look up the mount table entry; reading a path from stdin is not meaningful, matching GNU stat behavior. It is a usage/argument-validation error, not an I/O failure.

Source

Thrown at crates/pi-builtins/src/stat.rs:145

-`%t`: file system type in hex
-`%T`: file system type in human readable form

NOTE: your shell may have its own version of stat, which usually supersedes
the version described here.  Please refer to your shell's documentation
for details about the options it supports.";

	#[derive(Debug, Error)]
	enum StatError {
		#[error("Invalid quoting style: {style}")]
		InvalidQuotingStyle { style: String },
		#[error("missing operand\nTry 'stat --help' for more information.")]
		MissingOperand,
		#[error("{directive}: invalid directive")]
		InvalidDirective { directive: String },
		#[error("cannot read table of mounted file systems: {error}")]
		#[cfg_attr(not(unix), allow(dead_code, reason = "mount tables are unix-only"))]
		CannotReadFilesystem { error: String },
		#[error("using '-' to denote standard input does not work in file system mode")]
		#[cfg_attr(not(unix), allow(dead_code, reason = "stdin filesystem mode is unix-only"))]
		StdinFilesystemMode,
		#[error("cannot read file system information for {file}: {error}")]
		CannotReadFilesystemInfo { file: String, error: String },
		#[error("cannot stat {file}: {error}")]
		CannotStat { file: String, error: String },
	}

	mod options {
		pub const DEREFERENCE: &str = "dereference";
		pub const FILE_SYSTEM: &str = "file-system";
		pub const FORMAT: &str = "format";
		pub const PRINTF: &str = "printf";
		pub const TERSE: &str = "terse";
		pub const BSD_SHELL: &str = "bsd-shell";
		pub const BSD_TIMEFMT: &str = "bsd-timefmt";
		pub const FILES: &str = "files";
	}

View on GitHub (pinned to 9690622007)

Solutions

  1. Replace '-' with an actual filesystem path operand, e.g. `stat --file-system /`.
  2. If stdin-based stat is desired, drop the --file-system option (plain stat mode accepts '-') and resolve the path yourself.
  3. Guard scripts: only pass '-' to stat when file-system mode is off.

Example fix

// before
stat --file-system -

// after
stat --file-system /
Defensive patterns

Strategy: validation

Validate before calling

if (useFsMode && operand === '-') {
  throw new Error("stat file-system mode requires a real path, not '-'");
}

Try / catch

try {
  await stat.run(['--file-system', operand]);
} catch (err) {
  if (String(err).includes("does not work in file system mode")) {
    console.error(`replace '-' with a filesystem path when using --file-system`);
  } else throw err;
}

Prevention

When it happens

Trigger: Invoking the stat builtin with the `--file-system` option and '-' as the operand, e.g. piping data and running `echo / | stat --file-system -`.

Common situations: Scripts that build stat commands dynamically and pass '-' as a placeholder operand; porting GNU stat scripts where '-' handling differs between modes; pipelines where a filename is expected on stdin.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/69cfab031f61d4fc. Report an issue: GitHub.