{"record":{"id":"f091e0b96c9b0302","repo":"can1357/oh-my-pi","slug":"cannot-create-temporary-file-in","errorCode":null,"errorMessage":"cannot create temporary file in {}:","messagePattern":"cannot create temporary file in (.+?):","errorType":"exception","errorClass":"SortError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/sort.rs","lineNumber":2614,"sourceCode":"\t#[error(\"{}\", format_disorder(.file, .line_number, .line, .silent))]\n\tDisorder { file: OsString, line_number: usize, line: String, silent: bool },\n\n\t#[error(\"open failed: {}: {}\", .path.maybe_quote(), strip_errno(.error))]\n\tOpenFailed { path: PathBuf, error: std::io::Error },\n\n\t#[error(\"cannot read: {}: {}\", .path.maybe_quote(), strip_errno(.error))]\n\tReadFailed { path: PathBuf, error: std::io::Error },\n\n\t#[error(\"failed to open temporary file: {}\", strip_errno(.error))]\n\tOpenTmpFileFailed { error: std::io::Error },\n\n\t#[error(\"could not run compress program '{}': {}\", .prog, strip_errno(.error))]\n\tCompressProgExecutionFailed { prog: String, error: std::io::Error },\n\n\t#[error(\"{} terminated abnormally\", .prog.quote())]\n\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}","sourceCodeStart":2596,"sourceCodeEnd":2632,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/sort.rs#L2596-L2632","documentation":"SortError::TmpFileCreationFailed is thrown by the sort builtin when it cannot create a temporary file in the directory it selected for spilling (e.g. TMPDIR, the output file's directory with --compress-program, or -T path). It mirrors GNU coreutils' sort failure when open/mkstemp on the temp file fails. The quoted path tells you which directory was unusable.","triggerScenarios":"Running the sort builtin with data large enough to require spilling to a temp file while the temp directory is read-only, nonexistent, full, or explicitly set via -T/--temp-dir to an invalid path; also when --compress-program is in use and temp files must be created in the output file's directory.","commonSituations":"TMPDIR pointing at a removed or permission-restricted directory; read-only filesystem or full disk; sandboxed/container environments where /tmp is not writable; -T given a path that doesn't exist.","solutions":["Check the quoted path in the message: verify the directory exists and is writable (ls -ld <path>, touch <path>/.probe).","Set TMPDIR (or pass -T/--temp-dir) to a writable directory with enough free space (df -h <dir>).","Free disk space or clean stale temp files if the filesystem is full.","If using --compress-program, confirm the temp directory chosen (the output file's directory) is writable, or move output to a writable location."],"exampleFix":"// before: sort -T /var/tmp/data (dir missing/readonly)\n// after: ensure it exists or point elsewhere\n$ mkdir -p /var/tmp/data\n$ sort -T /var/tmp/data big.txt -o out.txt\n# or\n$ TMPDIR=/tmp sort big.txt -o out.txt","handlingStrategy":"validation","validationCode":"import * as fs from \"node:fs\";\n// before invoking sort with a temp dir / TMPDIR, ensure it is usable\nconst dir = process.env.TMPDIR ?? \"/tmp\";\nconst st = fs.statSync(dir);\nif (!st.isDirectory()) throw new Error(`temp dir not a directory: ${dir}`);\nfs.accessSync(dir, fs.constants.W_OK); // throws if not writable","typeGuard":null,"tryCatchPattern":"try {\n  await sort(input, { tempDir });\n} catch (err) {\n  if (String(err).includes(\"cannot create temporary file\")) {\n    // retry with a guaranteed-writable temp dir\n    await sort(input, { tempDir: os.tmpdir() });\n  } else throw err;\n}","preventionTips":["Always verify TMPDIR/-T targets exist and are writable before sorting large inputs.","Monitor free disk space on the temp filesystem in long-running pipelines.","In containers, mount or create a dedicated writable temp directory.","Prefer explicit -T paths over inheriting ambient TMPDIR in scripts."],"tags":["filesystem","temporary-files","sort","io"],"backgroundTag":"temp-file-creation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}