{"record":{"id":"6a3b186c35b19c78","repo":"can1357/oh-my-pi","slug":"write-failed","errorCode":null,"errorMessage":"write failed: {}: {}","messagePattern":"write failed: (.+?): (.+?)","errorType":"exception","errorClass":"SortError","httpStatus":null,"severity":"error","filePath":"crates/pi-builtins/src/sort.rs","lineNumber":2593,"sourceCode":"\t}\n}\n\nconst NEGATIVE: &u8 = &b'-';\nconst POSITIVE: &u8 = &b'+';\n\n// The automatic buffer heuristics clamp to this range to avoid\n// over-committing memory on constrained systems while still keeping\n// reasonably large chunks for typical workloads.\nconst MIN_AUTOMATIC_BUF_SIZE: usize = 512 * 1024; // 512 KiB\nconst FALLBACK_AUTOMATIC_BUF_SIZE: usize = 32 * 1024 * 1024; // 32 MiB\nconst MAX_AUTOMATIC_BUF_SIZE: usize = 1024 * 1024 * 1024; // 1 GiB\n\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())]","sourceCodeStart":2575,"sourceCodeEnd":2611,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/crates/pi-builtins/src/sort.rs#L2575-L2611","documentation":"`SortError::WriteFailed` occurs when the sort builtin cannot write to a file (typically a temporary chunk file during external merge sorting or the output sink). The message quotes the path and the errno-stripped OS error. This usually means disk, permissions, or space issues.","triggerScenarios":"Sorting data large enough to spill to temporary files, where writing a chunk to disk fails (EACCES, ENOSPC, EROFS, deleted temp dir), or failing to write the final output file.","commonSituations":"Full disk or quota while sorting huge files; TMPDIR pointing to a read-only or non-existent location; permissions on the output path.","solutions":["Check free disk space (`df -h`) and free space if ENOSPC.","Verify the output/temp directory exists and is writable (`ls -ld`, check $TMPDIR).","Confirm write permissions on the target file/directory for the running user.","Point TMPDIR to a writable location with enough capacity."],"exampleFix":"// before\nTMPDIR=/nonexistent sort --compress-program=gz big.txt\n\n// after\nTMPDIR=/tmp sort --compress-program=gz big.txt","handlingStrategy":"try-catch","validationCode":"// before sorting\nlet out = std::fs::metadata(&out_dir)?;\nif !out.is_dir() { eprintln!(\"output target must be a directory\"); }\nlet free = available_space(&out_dir); // check ENOSPC risk\nif free < required_estimate { eprintln!(\"insufficient disk space\"); }","typeGuard":null,"tryCatchPattern":"match sort_result {\n    Err(SortError::WriteFailed { path, error }) => {\n        eprintln!(\"write to {} failed: {error}; check disk space and permissions\", path.display());\n    }\n    Err(e) => eprintln!(\"sort: {e}\"),\n    Ok(_) => {}\n}","preventionTips":["Monitor free space on the output and temp filesystems before large sorts.","Keep TMPDIR on a writable, adequately sized volume.","Run sorts as a user with write access to output and temp directories."],"tags":["sort","io","filesystem","write"],"backgroundTag":"file-write-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}