can1357/oh-my-pi · error · SortError

when reading file names from standard input, no file name of

Error message

when reading file names from standard input, no file name of '-' allowed

What it means

SortError::MinusInStdIn is thrown when the --files0-from list (read from standard input via `--files0-from=-`) contains the entry `-`. Since the list itself is already being read from stdin, `-` has no meaning as a file name and GNU-compatible sort rejects it explicitly.

Source

Thrown at crates/pi-builtins/src/sort.rs:2624

	OpenTmpFileFailed { error: std::io::Error },

	#[error("could not run compress program '{}': {}", .prog, strip_errno(.error))]
	CompressProgExecutionFailed { prog: String, error: std::io::Error },

	#[error("{} terminated abnormally", .prog.quote())]
	CompressProgTerminatedAbnormally { prog: String },

	#[error("cannot create temporary file in {}:", .path.quote())]
	TmpFileCreationFailed { path: PathBuf },

	#[error("extra operand {}\nfile operands cannot be combined with --files0-from\nTry 'sort --help' for more information.", .file.quote())]
	FileOperandsCombined { file: PathBuf },


	#[error("multiple output files specified")]
	MultipleOutputFiles,

	#[error("when reading file names from standard input, no file name of '-' allowed")]
	MinusInStdIn,

	#[error("no input from {}", .file.quote())]
	EmptyInputFile { file: PathBuf },

	#[error("{}:{}: invalid zero-length file name", .file.maybe_quote(), .line_num)]
	ZeroLengthFileName { file: PathBuf, line_num: usize },
}

impl SortError {
	fn message(message: impl Into<String>) -> Self {
		Self::Message(message.into())
	}

	fn code(&self) -> i32 {
		if matches!(self, Self::Disorder { .. }) { 1 } else { 2 }
	}
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Remove `-` entries from the NUL-separated list before feeding it to --files0-from=-.
  2. Replace `-` with the actual path if a real file was intended.
  3. Filter the list: e.g. `printf '%s\0' ... | grep -zv '^-$' | sort --files0-from=-`.

Example fix

// before
printf 'a.txt\0-\0b.txt\0' | sort --files0-from=-
// after
printf 'a.txt\0b.txt\0' | sort --files0-from=-
Defensive patterns

Strategy: validation

Validate before calling

// sanitize a NUL-separated stdin list before --files0-from=-
const entries = list.split("\0").filter(e => e !== "" && e !== "-");
const cleaned = entries.join("\0") + "\0";
// pipe `cleaned` to sort --files0-from=-

Type guard

const isValidEntry = (e: string): boolean => e.length > 0 && e !== "-";

Try / catch

try {
  await sort(["--files0-from=-"], { stdin: listStream });
} catch (err) {
  if (String(err).includes("no file name of '-' allowed")) {
    await sort(["--files0-from=-"], { stdin: stripMinusEntries(listStream) });
  } else throw err;
}

Prevention

When it happens

Trigger: Piping a NUL-separated file list to `sort --files0-from=-` where one of the entries is the literal string `-`, e.g. `printf 'a.txt\0-\0' | sort --files0-from=-`.

Common situations: Generated file lists that include `-` as a placeholder for stdin; tools like find/du output post-processing where '-' sneaks in from other command conventions.

Related errors


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