can1357/oh-my-pi · error · SortError
cannot create temporary file in {}:
Error message
cannot create temporary file in {}: What it means
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.
Source
Thrown at crates/pi-builtins/src/sort.rs:2614
#[error("{}", format_disorder(.file, .line_number, .line, .silent))]
Disorder { file: OsString, line_number: usize, line: String, silent: bool },
#[error("open failed: {}: {}", .path.maybe_quote(), strip_errno(.error))]
OpenFailed { path: PathBuf, error: std::io::Error },
#[error("cannot read: {}: {}", .path.maybe_quote(), strip_errno(.error))]
ReadFailed { path: PathBuf, error: std::io::Error },
#[error("failed to open temporary file: {}", strip_errno(.error))]
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 },
}View on GitHub (pinned to 9690622007)
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.
Example fix
// before: sort -T /var/tmp/data (dir missing/readonly) // after: ensure it exists or point elsewhere $ mkdir -p /var/tmp/data $ sort -T /var/tmp/data big.txt -o out.txt # or $ TMPDIR=/tmp sort big.txt -o out.txt
Defensive patterns
Strategy: validation
Validate before calling
import * as fs from "node:fs";
// before invoking sort with a temp dir / TMPDIR, ensure it is usable
const dir = process.env.TMPDIR ?? "/tmp";
const st = fs.statSync(dir);
if (!st.isDirectory()) throw new Error(`temp dir not a directory: ${dir}`);
fs.accessSync(dir, fs.constants.W_OK); // throws if not writable Try / catch
try {
await sort(input, { tempDir });
} catch (err) {
if (String(err).includes("cannot create temporary file")) {
// retry with a guaranteed-writable temp dir
await sort(input, { tempDir: os.tmpdir() });
} else throw err;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- write failed: {}: {}
- open failed: {}: {}
- cannot read: {}: {}
- Too many levels of symbolic links
- {}: {error}
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/f091e0b96c9b0302.
Report an issue: GitHub.