denoland/deno · error · AnyError

Failed to unpack archive.

Error message

Failed to unpack archive.

What it means

`unpack_into_dir` extracts downloaded zips with the zip crate and, when that fails or produces no executable, falls back to shelling out to `unzip` (unix) or `tar.exe` (Windows) in `unzip_with_shell`. This error means the fallback child process ran to completion but exited non-zero: the external tool saw the archive bytes and still could not extract them. A missing `unzip` produces a different, explicit 'not found in your PATH' io error instead.

Source

Thrown at cli/util/archive.rs:55

    Command::new("unzip")
      .current_dir(dest_path)
      .arg(archive_path)
      .spawn()
      .map_err(|err| {
        if err.kind() == std::io::ErrorKind::NotFound {
          std::io::Error::new(
            std::io::ErrorKind::NotFound,
            "`unzip` was not found in your PATH, please install `unzip`",
          )
        } else {
          err
        }
      })?
      .wait()?
  };

  if !unpack_status.success() {
    bail!("Failed to unpack archive.");
  }

  Ok(())
}

fn unzip(
  archive_name: &str,
  archive_data: &[u8],
  dest_path: &Path,
) -> Result<(), AnyError> {
  let mut archive = zip::ZipArchive::new(std::io::Cursor::new(archive_data))?;
  archive
    .extract(dest_path)
    .with_context(|| format!("failed to extract archive: {archive_name}"))?;

  Ok(())
}

View on GitHub (pinned to 9ad36f7a2c)

Solutions

  1. Check free space and write permissions on TMPDIR and DENO_DIR (`df -h`, touch a file), then retry.
  2. Delete the cached download so it is fetched fresh: remove the relevant folders under DENO_DIR (e.g. dl/deps caches) and re-run the command.
  3. Verify the cached archive directly with `unzip -t <file>.zip`; if it reports errors, the download was corrupted — clear the cache and re-download.
  4. In sandboxed setups, ensure the `unzip`/`tar.exe` child process has the same filesystem permissions as Deno itself.

Example fix

# before: 'Failed to unpack archive.' during deno upgrade
df -h "$TMPDIR" "${DENO_DIR:-$HOME/.cache/deno}"      # rule out ENOSPC
rm -rf "${DENO_DIR:-$HOME/.cache/deno}/dl"            # drop cached downloads
deno upgrade                                           # re-download and unpack
Defensive patterns

Strategy: retry

Validate before calling

# validate the cached archive before extraction attempts
unzip -t "$archive" >/dev/null 2>&1 || echo "corrupt archive — delete and re-download"

Try / catch

// one clean retry after removing partial output
let exe = match unpack_into_dir(args.clone()) {
  Ok(p) => p,
  Err(e) if e.to_string().contains("Failed to unpack archive") => {
    let _ = std::fs::remove_dir_all(&dest); // clear partial extraction
    unpack_into_dir(args)? // retry with clean state
  }
  Err(e) => return Err(e),
};

Prevention

When it happens

Trigger: The zip-crate path fails (corrupt/truncated download, disk full mid-extract, unwritable destination) and the shell fallback also exits non-zero. Typical during `deno upgrade` or first-run toolchain downloads when a proxy truncated the body, TMPDIR/DENO_DIR is full or read-only, or the cached zip is damaged and reused.

Common situations: Flaky corporate proxies corrupting downloaded zips; CI runners with tiny tmpfs filling up; sandboxed environments where unzip cannot write to the destination; a corrupted download cache that keeps serving the same bad archive across retries.

Related errors


AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20). Data as JSON: /api/errors/4d2a7134d47f7ac0. Report an issue: GitHub.