can1357/oh-my-pi · error · SortError

{}:{}: invalid zero-length file name

Error message

{}:{}: invalid zero-length file name

What it means

SortError::ZeroLengthFileName is thrown when a file list read via --files0-from contains an empty (zero-length) file name at a given line. GNU-compatible sort reports the list file and line number because an empty name cannot refer to any file. Carries both the list file path and the line number of the offending entry.

Source

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

	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 }
	}
}

// refs are required because this fn is used by thiserror macro
#[expect(clippy::trivially_copy_pass_by_ref)]
fn format_disorder(file: &OsString, line_number: &usize, line: &String, silent: &bool) -> String {
	if *silent {
		String::new()

View on GitHub (pinned to 9690622007)

Solutions

  1. Fix the list generator to never emit empty entries (skip unset/empty variables before printing).
  2. Filter empties from the list: `grep -zv '^$' list.nul | sort --files0-from=-`.
  3. Use the reported line number in the message to locate and correct the bad entry in the list file.
  4. Validate the list before use: split on NUL and assert each entry is non-empty.

Example fix

// before: may emit empty entries
printf '%s\0' "$f1" "$f2" "$f3" > list.nul
// after: drop empties
printf '%s\0' "$f1" "$f2" "$f3" | grep -zv '^$' > list.nul
Defensive patterns

Strategy: validation

Validate before calling

// validate a NUL-separated list: no empty entries
const entries = list.split("\0");
const bad = entries.findIndex(e => e === "");
if (bad !== -1) throw new Error(`empty file name at entry ${bad + 1}`);

Type guard

const isNonEmptyName = (name: string): boolean => name.length > 0;

Try / catch

try {
  await sort([`--files0-from=${listFile}`]);
} catch (err) {
  const m = String(err).match(/^(.*):(\d+): invalid zero-length file name$/);
  if (m) {
    // use reported line number to repair the list, then retry
    rewriteListDroppingEmptyEntries(listFile, Number(m[2]));
    await sort([`--files0-from=${listFile}`]);
  } else throw err;
}

Prevention

When it happens

Trigger: A NUL-separated list consumed by --files0-from containing consecutive NUL bytes (`\0\0`) or a stray empty entry, e.g. produced by `find ... -print0` over names joined incorrectly or by buggy list generation.

Common situations: Buggy generators that emit `printf '%s\0'` with unset/empty variables; concatenating two NUL-separated lists without deduplication; records produced from empty fields in upstream data.

Related errors


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