{"record":{"id":"ca8db211ae51f762","repo":"wasmerio/wasmer","slug":"failed-to-unpack-with-parent-e","errorCode":null,"errorMessage":"failed to unpack (with parent) {}: {e}","messagePattern":"failed to unpack \\(with parent\\) (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/cli/src/utils/unpack.rs","lineNumber":69,"sourceCode":"        lzma_rs::xz_decompress(&mut bufread, &mut decomp).map_err(|e| {\n            anyhow::anyhow!(\n                \"failed to unpack (try_decode_xz) {}: {e}\",\n                target_targz_path.display()\n            )\n        })?;\n\n        let cursor = std::io::Cursor::new(decomp);\n        let mut ar = tar::Archive::new(cursor);\n        if strip_toplevel {\n            unpack_sans_parent(ar, target_path).map_err(|e| {\n                anyhow::anyhow!(\n                    \"failed to unpack (sans parent) {}: {e}\",\n                    target_targz_path.display()\n                )\n            })\n        } else {\n            ar.unpack(target_path).map_err(|e| {\n                anyhow::anyhow!(\n                    \"failed to unpack (with parent) {}: {e}\",\n                    target_targz_path.display()\n                )\n            })\n        }\n    };\n\n    try_decode_gz().or_else(|e1| {\n        try_decode_xz()\n            .map_err(|e2| anyhow::anyhow!(\"could not decode gz: {e1}, could not decode xz: {e2}\"))\n    })?;\n\n    Ok(Path::new(&target_targz_path).to_path_buf())\n}\n\npub fn unpack_with_parent<R>(mut archive: tar::Archive<R>, dst: &Path) -> Result<(), anyhow::Error>\nwhere\n    R: std::io::Read,","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/wasmerio/wasmer/blob/8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5/lib/cli/src/utils/unpack.rs#L51-L87","documentation":"try_unpack_targz in lib/cli/src/utils/unpack.rs extracts a downloaded .tar.gz archive with the `tar` crate. When `ar.unpack(target_path)` fails (an entry cannot be read, decompressed, or written to disk), it wraps the io error in this message identifying the archive path and whether the parent directory was preserved. It is a wrapper around tar extraction, not a download failure.","triggerScenarios":"Calling try_unpack_targz on a corrupt or truncated .tar.gz, on an archive containing entries whose paths escape or cannot be created under target_path, or when the target directory is unwritable (permissions, disk full, path too long).","commonSituations":"Interrupted download leaving a partial archive cached locally; antivirus or another process locking files in the target dir on Windows; extracting an archive built with unusual entry permissions or symlinks into a read-only install directory.","solutions":["Delete the cached archive file and re-download it; a truncated gzip stream is the most common cause.","Check the target directory exists and is writable (mkdir -p, fix permissions).","Verify the archive integrity manually: `tar -tzf <file>` should list entries without errors.","Free disk space / shorten the target path if extraction fails mid-write.","Check the inner `{e}` message for the specific entry and I/O error to pinpoint the cause."],"exampleFix":"// before: reusing a possibly stale cache\ndownload(url, &target_targz_path)?;\ntry_unpack_targz(&target_targz_path, &dir, false)?;\n// after: remove stale cache first\nif target_targz_path.exists() {\n    std::fs::remove_file(&target_targz_path)?;\n}\ndownload(url, &target_targz_path)?;\nstd::fs::create_dir_all(&dir)?;\ntry_unpack_targz(&target_targz_path, &dir, false)?;","handlingStrategy":"validation","validationCode":"// verify archive is readable and target dir writable before unpacking\nfn precheck(archive: &Path, target: &Path) -> anyhow::Result<()> {\n    let f = std::fs::File::open(archive)?;\n    let mut gz = flate2::read::GzDecoder::new(f);\n    let mut tar = tar::Archive::new(&mut gz);\n    tar.entries()?.count(); // fails fast on corrupt archive\n    anyhow::ensure!(target.is_dir(), \"target dir missing: {}\", target.display());\n    let probe = target.join(\".wprobe\");\n    std::fs::write(&probe, b\"\")?;\n    std::fs::remove_file(&probe)?;\n    Ok(())\n}","typeGuard":null,"tryCatchPattern":"match try_unpack_targz(&archive, &dir, false) {\n    Ok(p) => p,\n    Err(e) if e.to_string().contains(\"failed to unpack\") => {\n        std::fs::remove_file(&archive).ok(); // drop corrupt cache\n        re_download_and_unpack(&archive, &dir)?\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Re-download the archive when unpack fails instead of retrying the corrupt file","Verify checksums/size after download and before unpack","Always create the target directory with create_dir_all before extraction","Run extraction under the same user that owns the target directory"],"tags":["rust","archive","tar","filesystem","unpack"],"backgroundTag":"archive-extraction-failed","analyzedSha":"8c4b9ee9d33fb2068863fbb3d328683e7e6ff7f5","analyzedAt":"2026-09-01T23:06:31.009Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}