{"record":{"id":"a41b015ed5b2294e","repo":"can1357/oh-my-pi","slug":"invalid-zero-length-file-name","errorCode":null,"errorMessage":"{}:{}: invalid zero-length file name","messagePattern":"(.+?):(.+?): invalid zero-length file name","errorType":"exception","errorClass":"SortError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/sort.rs","lineNumber":2630,"sourceCode":"\tCompressProgTerminatedAbnormally { prog: String },\n\n\t#[error(\"cannot create temporary file in {}:\", .path.quote())]\n\tTmpFileCreationFailed { path: PathBuf },\n\n\t#[error(\"extra operand {}\\nfile operands cannot be combined with --files0-from\\nTry 'sort --help' for more information.\", .file.quote())]\n\tFileOperandsCombined { file: PathBuf },\n\n\n\t#[error(\"multiple output files specified\")]\n\tMultipleOutputFiles,\n\n\t#[error(\"when reading file names from standard input, no file name of '-' allowed\")]\n\tMinusInStdIn,\n\n\t#[error(\"no input from {}\", .file.quote())]\n\tEmptyInputFile { file: PathBuf },\n\n\t#[error(\"{}:{}: invalid zero-length file name\", .file.maybe_quote(), .line_num)]\n\tZeroLengthFileName { file: PathBuf, line_num: usize },\n}\n\nimpl SortError {\n\tfn message(message: impl Into<String>) -> Self {\n\t\tSelf::Message(message.into())\n\t}\n\n\tfn code(&self) -> i32 {\n\t\tif matches!(self, Self::Disorder { .. }) { 1 } else { 2 }\n\t}\n}\n\n// refs are required because this fn is used by thiserror macro\n#[expect(clippy::trivially_copy_pass_by_ref)]\nfn format_disorder(file: &OsString, line_number: &usize, line: &String, silent: &bool) -> String {\n\tif *silent {\n\t\tString::new()","sourceCodeStart":2612,"sourceCodeEnd":2648,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/sort.rs#L2612-L2648","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the list generator to never emit empty entries (skip unset/empty variables before printing).","Filter empties from the list: `grep -zv '^$' list.nul | sort --files0-from=-`.","Use the reported line number in the message to locate and correct the bad entry in the list file.","Validate the list before use: split on NUL and assert each entry is non-empty."],"exampleFix":"// before: may emit empty entries\nprintf '%s\\0' \"$f1\" \"$f2\" \"$f3\" > list.nul\n// after: drop empties\nprintf '%s\\0' \"$f1\" \"$f2\" \"$f3\" | grep -zv '^$' > list.nul","handlingStrategy":"validation","validationCode":"// validate a NUL-separated list: no empty entries\nconst entries = list.split(\"\\0\");\nconst bad = entries.findIndex(e => e === \"\");\nif (bad !== -1) throw new Error(`empty file name at entry ${bad + 1}`);","typeGuard":"const isNonEmptyName = (name: string): boolean => name.length > 0;","tryCatchPattern":"try {\n  await sort([`--files0-from=${listFile}`]);\n} catch (err) {\n  const m = String(err).match(/^(.*):(\\d+): invalid zero-length file name$/);\n  if (m) {\n    // use reported line number to repair the list, then retry\n    rewriteListDroppingEmptyEntries(listFile, Number(m[2]));\n    await sort([`--files0-from=${listFile}`]);\n  } else throw err;\n}","preventionTips":["Guard list generators against unset/empty variables before emitting entries.","Filter lists with grep -zv '^$' before passing to --files0-from.","Never concatenate NUL-separated lists without checking for doubled NULs.","Validate list contents (split on NUL, assert non-empty) in tests."],"tags":["sort","input-validation","files0-from","usage-error"],"backgroundTag":"invalid-input-entry","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}