{"id":"2e647dcd56b71679","repo":"rust-lang/rust","slug":"context-err","errorCode":null,"errorMessage":"{context}: {err}","messagePattern":"\\{context\\}: \\{err\\}","errorType":"exception","errorClass":null,"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/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_ssa/src/back/archive.rs#L703-L723","documentation":"This is the io_error_context helper, not a standalone error. It wraps an underlying io::Error with a descriptive prefix so that low-level filesystem failures during archive writing carry context about which operation failed. Within archive.rs it prefixes two operations: 'failed to rename archive file' (the atomic rename of the temp archive to its final path) and 'failed to remove temporary directory' (cleaning up the temp dir). The {err} part is the original OS error.","triggerScenarios":"Produced when fs::rename of the freshly written temp archive to the output path fails, or when tempdir cleanup fails. The prefix tells you which step; the suffix carries the OS-level reason (permission denied, cross-device, busy, etc.).","commonSituations":"Output path on a different filesystem/mount than the temp dir, making the atomic rename a cross-device move that the OS rejects. Permission/ownership mismatch on the target directory. Antivirus or file-locking software (common on Windows) holding the output file open. The destination being read-only or on a full disk.","solutions":["Ensure TMPDIR / cargo target dir and the final output path are on the same filesystem/mount.","Check write permissions and free disk space on the output directory.","On Windows, disable or exclude the target directory from antivirus/on-access scanning and close editors/IDEs holding the file.","Retry the build after clearing stale locks; if it persists, capture the OS errno from {err} and address it specifically."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Generic wrapper around an underlying archive error.\n// Pre-flight: try to open and parse the archive so the\n// underlying error surfaces before rustc sees it.\nfn archive_preflight(path: &std::path::Path) -> Result<(), String> {\n    std::process::Command::new(\"ar\")\n        .args([\"t\", path.to_str().unwrap()])\n        .output()\n        .map_err(|e| e.to_string())\n        .and_then(|o| {\n            if o.status.success() { Ok(()) }\n            else { Err(format!(\"{}\", String::from_utf8_lossy(&o.stderr))) }\n        })\n}","typeGuard":"fn is_openable_archive(path: &std::path::Path) -> bool {\n    archive_preflight(path).is_ok()\n}","tryCatchPattern":"// The message is \"{context}: {err}\"; parse the context to classify.\nlet stderr = String::from_utf8_lossy(&output.stderr);\nfor line in stderr.lines() {\n    if let Some((ctx, err)) = line.split_once(\": \") {\n        report(ResolveError::Archive { context: ctx.into(), detail: err.into() });\n    }\n}","preventionTips":["Run the archive preflight above for every native dependency before `cargo build`.","Surface the `{context}` portion to users so the underlying OS/tool error is not lost.","Keep `llvm-ar`/`ar` on PATH and at a version compatible with the archive format."],"tags":["archive","io","filesystem","rename","windows"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}