can1357/oh-my-pi · error · SortError
failed to open temporary file
Error message
failed to open temporary file: {} What it means
`SortError::OpenTmpFileFailed` is raised when the sort builtin cannot create/open one of its internal temporary files, carrying only the stripped errno. Sort uses temp files when the input exceeds memory limits, so this failure blocks large sorts.
Solutions
- Free space on the temp filesystem or point TMPDIR to a larger mount.
- Ensure TMPDIR exists and is writable by the current user.
- Reduce memory buffer (`-S`) so the input fits in memory, avoiding temp files.
- In containers, mount a writable tmpfs with sufficient size.
Example fix
// before TMPDIR=/readonly sort -S 10M huge.txt // after TMPDIR=/var/tmp sort -S 10M huge.txt
Defensive patterns
Strategy: validation
Validate before calling
let tmp = std::env::var_os("TMPDIR").unwrap_or_else(|| "/tmp".into());
let probe = std::env::temp_dir().join(".sort_probe");
if std::fs::write(&probe, b"x").is_err() {
eprintln!("temp dir {tmp:?} is not writable; set TMPDIR appropriately");
}
let _ = std::fs::remove_file(&probe); Try / catch
match sort_result {
Err(SortError::OpenTmpFileFailed { error }) => {
eprintln!("temp file open failed: {error}; check TMPDIR space/permissions");
}
Err(e) => eprintln!("sort: {e}"),
Ok(_) => {}
} Prevention
- Keep TMPDIR writable and sized for the largest expected sort spill.
- Raise the memory buffer (-S) when the input can fit in RAM, avoiding temp files.
- In containers, mount a sufficiently large writable tmpfs for /tmp.
When it happens
Trigger: Sorting input larger than the in-memory buffer, forcing a temp-file spill, when tmpdir creation/open fails (no space, unwritable TMPDIR, no temp dir available).
Common situations: ENOSPC on the temp filesystem; TMPDIR pointing somewhere read-only; sandboxed/containers with restricted /tmp.
Related errors
- cannot create temporary file in
- cannot read
- failed to create a unique fc temporary file
- no input from
- open failed
AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31).
Data as JSON: /api/errors/36c989c93f014531.
Report an issue: GitHub.
Appendix: source
Thrown at crates/pi-builtins/src/sort.rs:2605
#[derive(Debug, Error)]
pub enum SortError {
#[error("{0}")]
Message(String),
#[error("write failed: {}: {}", .path.maybe_quote(), strip_errno(.error))]
WriteFailed { path: OsString, error: std::io::Error },
#[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,
View on GitHub (pinned to 9690622007)