{"record":{"id":"2e647dcd56b71679","repo":"rust-lang/rust","slug":"context-err","errorCode":null,"errorMessage":"{context}: {err}","messagePattern":"\\{context\\}: \\{err\\}","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_ssa/src/back/archive.rs","lineNumber":721,"sourceCode":"\n        let any_entries = !entries.is_empty();\n        drop(entries);\n        // Drop src_archives to unmap all input archives, which is necessary if we want to write the\n        // output archive to the same location as an input archive on Windows.\n        drop(self.src_archives);\n\n        fs::rename(archive_tmpfile_path, output)\n            .map_err(|err| io_error_context(\"failed to rename archive file\", err))?;\n        archive_tmpdir\n            .close()\n            .map_err(|err| io_error_context(\"failed to remove temporary directory\", err))?;\n\n        Ok(any_entries)\n    }\n}\n\nfn io_error_context(context: &str, err: io::Error) -> io::Error {\n    io::Error::new(io::ErrorKind::Other, format!(\"{context}: {err}\"))\n}\n","sourceCodeStart":703,"sourceCodeEnd":723,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_codegen_ssa/src/back/archive.rs#L703-L723","documentation":"This is the io_error_context helper function (archive.rs:720-722), not a standalone error. It wraps any std::io::Error with a context prefix string and is used throughout ArArchiveBuilder::build_inner for operations including opening object files, memory-mapping, creating temp directories, creating temp files, renaming the final archive, flushing, and removing temp dirs. The {context} identifies which step failed; {err} carries the OS-level error message.","triggerScenarios":"Any IO failure during archive building: 'failed to open object file' (permission denied or missing file), 'failed to map object file' (mmap failure), 'couldn't create a directory for the temp file' (disk full or permission denied on output dir), 'couldn't create the temp file', 'failed to rename archive file' (cross-device rename or target exists), 'failed to remove temporary directory'.","commonSituations":"Output directory is read-only or doesn't exist; disk full during archive write; insufficient file descriptors (ulimit); antivirus or file watcher locking temp files on Windows; NFS/network filesystem mmap issues; running out of inodes.","solutions":["Read the {context} prefix to identify which operation failed, then address the {err} cause directly.","For permission errors: ensure the output directory and all intermediate paths are writable by the build user.","For 'failed to map object file': check available memory and virtual address space; on Linux check /proc/sys/vm/max_map_count.","For temp file/rename errors: ensure the output path is on the same filesystem as the system temp dir, or set TMPDIR to a location on the same volume.","For disk-full: free space or redirect the build output to a larger volume."],"exampleFix":"# before: temp dir on a different filesystem than output, causing rename failure\nTMPDIR=/tmp cargo build --release  # output on /data, rename fails cross-device\n# after: set TMPDIR on the same filesystem as the output\nTMPDIR=/data/tmp cargo build --release","handlingStrategy":"try-catch","validationCode":"// Before building, verify the output directory is writable and has space.\nuse std::path::Path;\n\nfn verify_output_dir(path: &Path) -> Result<(), String> {\n    fs::create_dir_all(path).map_err(|e| format!(\"cannot create output dir {}: {}\", path.display(), e))?;\n    let test_file = path.join(\".write_test\");\n    std::fs::write(&test_file, b\"test\").map_err(|e| format!(\"output dir not writable: {}\", e))?;\n    std::fs::remove_file(&test_file).ok();\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"// io_error_context wraps io::Error; errors from build_inner propagate as\n// ArchiveBuildFailure fatal diagnostic. Guard at the build-system level:\n// ensure TMPDIR and the output directory are on the same filesystem.\n// In build scripts:\nif let Err(e) = std::fs::create_dir_all(&output_dir) {\n    eprintln!(\"cannot prepare output directory: {e}\");\n    std::process::exit(1);\n}","preventionTips":["Ensure TMPDIR is on the same filesystem as the build output to avoid cross-device rename failures.","Check ulimit -n (open file descriptors) for large builds.","Verify write permissions on the output directory before starting a build.","Monitor disk space — archive building is write-intensive."],"tags":["rustc","archive","io","codegen","operational"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}