chenhg5/cc-connect · error

gzip: %w

Error message

gzip: %w

What it means

extractFromTarGz wraps errors from gzip.NewReader as "gzip: %w". It means the downloaded archive file could not be opened as a gzip stream — the file is not gzip-compressed (or is corrupt) at the very first bytes.

Source

Thrown at cmd/cc-connect/update.go:324

// extractBinaryFromArchive extracts the cc-connect binary from a .tar.gz or .zip archive.
func extractBinaryFromArchive(archivePath, archiveName string) (string, error) {
	if strings.HasSuffix(archiveName, ".zip") {
		return extractFromZip(archivePath)
	}
	return extractFromTarGz(archivePath)
}

func extractFromTarGz(archivePath string) (string, error) {
	f, err := os.Open(archivePath)
	if err != nil {
		return "", err
	}
	defer f.Close()

	gz, err := gzip.NewReader(f)
	if err != nil {
		return "", fmt.Errorf("gzip: %w", err)
	}
	defer gz.Close()

	tr := tar.NewReader(gz)
	for {
		hdr, err := tr.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return "", fmt.Errorf("tar: %w", err)
		}
		if hdr.Typeflag != tar.TypeReg {
			continue
		}
		if strings.HasPrefix(hdr.Name, "cc-connect") {
			tmp, err := os.CreateTemp("", "cc-connect-update-*")
			if err != nil {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Inspect the file with `file <archive>` or `head -c 200 <archive>` — HTML text means the download fetched an error page; fix proxy or re-download
  2. Delete the cached/partial archive and retry the update so it re-downloads
  3. Verify the asset name matches your platform (tar.gz for Linux/macOS, zip for Windows) and that binaryAssetName(tag) targets the right file
  4. Verify asset checksums against the release notes before extraction

Example fix

// before
gz, err := gzip.NewReader(f)
if err != nil {
    return "", fmt.Errorf("gzip: %w", err)
}
// after
gz, err := gzip.NewReader(f)
if err != nil {
    return "", fmt.Errorf("gzip: %w (archive corrupt or not gzip; re-download the asset)", err)
}
Defensive patterns

Strategy: validation

Validate before calling

// validate the downloaded file is gzip before extraction:
head := make([]byte, 2)
f, _ := os.Open(archivePath)
io.ReadFull(f, head)
f.Close()
if head[0] != 0x1f || head[1] != 0x8b {
    return errors.New("downloaded file is not gzip — proxy error page or wrong asset?")
}

Try / catch

// Go: delete bad downloads and retry once
if _, err := extractBinaryFromArchive(path); err != nil {
    if strings.Contains(err.Error(), "gzip:") {
        os.Remove(path)
        if newPath := reDownload(assetURL); newPath != "" {
            _, err = extractBinaryFromArchive(newPath)
        }
    }
}

Prevention

When it happens

Trigger: gzip.NewReader(f) fails on the downloaded file: the file is actually an HTML error page saved as the asset (proxy served a 200 error page), the download was truncated/corrupted, wrong asset picked, or the release asset is a .zip instead of .tar.gz.

Common situations: Updating through a corporate proxy that substitutes HTML block pages; interrupted download leaving a partial file; picking the wrong asset (zip on Linux); asset replaced/removed on the release page; disk corruption in the temp/cache dir.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/02682b11f08359ca. Report an issue: GitHub.