{"record":{"id":"36c989c93f014531","repo":"can1357/oh-my-pi","slug":"failed-to-open-temporary-file","errorCode":null,"errorMessage":"failed to open temporary file: {}","messagePattern":"failed to open temporary file: (.+?)","errorType":"exception","errorClass":"SortError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/sort.rs","lineNumber":2605,"sourceCode":"\n#[derive(Debug, Error)]\npub enum SortError {\n\t#[error(\"{0}\")]\n\tMessage(String),\n\n\t#[error(\"write failed: {}: {}\", .path.maybe_quote(), strip_errno(.error))]\n\tWriteFailed { path: OsString, error: std::io::Error },\n\n\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","sourceCodeStart":2587,"sourceCodeEnd":2623,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/sort.rs#L2587-L2623","documentation":"`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.","triggerScenarios":"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).","commonSituations":"ENOSPC on the temp filesystem; TMPDIR pointing somewhere read-only; sandboxed/containers with restricted /tmp.","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."],"exampleFix":"// before\nTMPDIR=/readonly sort -S 10M huge.txt\n\n// after\nTMPDIR=/var/tmp sort -S 10M huge.txt","handlingStrategy":"validation","validationCode":"let tmp = std::env::var_os(\"TMPDIR\").unwrap_or_else(|| \"/tmp\".into());\nlet probe = std::env::temp_dir().join(\".sort_probe\");\nif std::fs::write(&probe, b\"x\").is_err() {\n    eprintln!(\"temp dir {tmp:?} is not writable; set TMPDIR appropriately\");\n}\nlet _ = std::fs::remove_file(&probe);","typeGuard":null,"tryCatchPattern":"match sort_result {\n    Err(SortError::OpenTmpFileFailed { error }) => {\n        eprintln!(\"temp file open failed: {error}; check TMPDIR space/permissions\");\n    }\n    Err(e) => eprintln!(\"sort: {e}\"),\n    Ok(_) => {}\n}","preventionTips":["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."],"tags":["sort","io","tempfile","disk-space"],"backgroundTag":"temp-file-open-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}