chenhg5/cc-connect · error

extract: %w

Error message

extract: %w

What it means

extractFromTarGz wraps errors from io.Copy(tmp, tr) as "extract: %w". The tar entry named cc-connect* was found and a temp file created, but streaming its contents into the temp file failed — either a decompression error mid-stream or a disk write error.

Source

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

		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
		}
	}
	return "", fmt.Errorf("binary not found in archive")
}

func extractFromZip(archivePath string) (string, error) {
	r, err := zip.OpenReader(archivePath)
	if err != nil {
		return "", fmt.Errorf("zip: %w", err)
	}
	defer r.Close()

	for _, f := range r.File {
		if !strings.HasPrefix(f.Name, "cc-connect") {
			continue

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check free disk space on the temp filesystem (df -h /tmp) and clean up
  2. Check /tmp permissions and mount flags (read-only, noexec, quota) and set TMPDIR to a writable location if needed
  3. Retry after fixing storage — if it recurs with plenty of space, the archive is likely corrupt; re-download
  4. Verify the extracted binary with a checksum comparison before swapping it in

Example fix

// before
if _, err := io.Copy(tmp, tr); err != nil {
    tmp.Close()
    os.Remove(tmp.Name())
    return "", fmt.Errorf("extract: %w", err)
}
// after
if _, err := io.Copy(tmp, tr); err != nil {
    tmp.Close()
    os.Remove(tmp.Name())
    return "", fmt.Errorf("extract: %w (check disk space on %s)", err, os.TempDir())
}
Defensive patterns

Strategy: fallback

Validate before calling

// ensure the temp volume can hold the archive before extracting:
var st syscall.Statfs_t
syscall.Statfs(os.TempDir(), &st)
free := int64(st.Bavail) * int64(st.Bsize)
info, _ := os.Stat(archivePath)
if free < info.Size()*3 { return errors.New("insufficient temp disk space for extraction") }

Try / catch

// Go: fall back to an alternate temp dir when extraction fails
out, err := extractFromTarGz(path)
if err != nil {
    if strings.Contains(err.Error(), "extract:") {
        os.Setenv("TMPDIR", "/var/tmp") // alternate writable location
        out, err = extractFromTarGz(path)
    }
    if err != nil { return err }
}

Prevention

When it happens

Trigger: io.Copy(tmp, tr) errors: disk full on the temp volume, write permission failure in os.TempDir(), or the gzip/tar stream corrupting mid-file (surfaces as a read error during the copy).

Common situations: Full or nearly-full disk (common in constrained CI containers); read-only or noexec /tmp; disk quota exceeded; archive corrupted partway through the binary entry.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


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