chenhg5/cc-connect · error
tar: %w
Error message
tar: %w
What it means
extractFromTarGz wraps errors from tar.Reader.Next() as "tar: %w". The gzip stream opened fine, but reading the tar entries inside it failed partway — the tar payload is corrupt or malformed after the header region.
Source
Thrown at cmd/cc-connect/update.go:335
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 {
return "", err
}
if _, err := io.Copy(tmp, tr); err != nil {
tmp.Close()
os.Remove(tmp.Name())
return "", fmt.Errorf("extract: %w", err)
}
tmp.Close()
return tmp.Name(), nil
}
}View on GitHub (pinned to 4000b2338a)
Solutions
- Re-download the archive (delete any cached copy) and retry — truncation is the most common cause
- Verify the archive integrity locally: `gzip -t file.tar.gz && tar -tf file.tar.gz`
- Compare the asset checksum with the value published in the release notes
- If persistent, inspect the release asset itself — it may be corrupted upstream
Example fix
// before
if err != nil {
return "", fmt.Errorf("tar: %w", err)
}
// after
if err != nil {
return "", fmt.Errorf("tar: %w (archive truncated or corrupt; re-download)", err)
} Defensive patterns
Strategy: validation
Validate before calling
// test archive integrity before extraction:
cmd := exec.Command("sh", "-c", fmt.Sprintf("gzip -t %s && tar -tzf %s >/dev/null", path, path))
if err := cmd.Run(); err != nil {
return errors.New("archive failed integrity check; re-download")
} Try / catch
// Go: treat mid-stream tar errors as corrupt-download
if _, err := extractFromTarGz(path); err != nil {
if strings.Contains(err.Error(), "tar:") {
os.Remove(path)
return errors.New("archive corrupt mid-stream; deleted and re-download required")
}
return err
} Prevention
- Compare downloaded bytes with the Content-Length before extracting
- Prefer checksums published with the release over size checks alone
- Don't hand-edit or recompress release archives
- Investigate CDN/cache layers serving corrupted copies if it recurs across hosts
When it happens
Trigger: tr.Next() returns a non-EOF error while iterating entries: truncated download (valid gzip header, cut-off tar), bit corruption, an asset that is gzip but not tar, or an I/O read error from disk while streaming.
Common situations: Flaky network truncated the download mid-archive; manually edited or re-compressed archive; CDN/cache serving a corrupted asset; filesystem read errors on the temp file.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/f129fbf9262656c1.
Report an issue: GitHub.