github/copilot-sdk · error

failed to create gzip reader

Error message

failed to create gzip reader: %w

What it means

The release package is a gzipped tar; extractCLILicense wraps the file in gzip.NewReader to stream it. If the gzip header cannot be read, this error wraps the failure. It means the file at tarballPath is not valid gzip data (corrupt, truncated, or not actually a .tar.gz).

Solutions

  1. Verify the file is a real gzip archive (file <tarball> or gzip -t).
  2. Re-download the release tarball; discard the corrupt copy.
  3. Check for proxy/VPN interference that could substitute HTML for the asset.
  4. Confirm checksum verification ran (buildBundle does) and the correct tarballPath was passed.

Example fix

// before: accepting any downloaded file without sanity check
// after: verify gzip magic before extraction
head := make([]byte, 2)
f, _ := os.Open(tarballPath)
io.ReadFull(f, head)
f.Close()
if head[0] != 0x1f || head[1] != 0x8b {
    return fmt.Errorf("tarball %s is not gzip data; re-download", tarballPath)
}
Defensive patterns

Strategy: validation

Validate before calling

// confirm gzip magic before treating the file as a release package
f, err := os.Open(tarballPath)
if err != nil { return err }
defer f.Close()
magic := make([]byte, 2)
if _, err := io.ReadFull(f, magic); err != nil || magic[0] != 0x1f || magic[1] != 0x8b {
    return fmt.Errorf("%s is not a gzip archive", tarballPath)
}

Try / catch

if err := buildBundle(...); err != nil {
    if strings.Contains(err.Error(), "failed to create gzip reader") {
        purgeCache(); reDownload(); return retryBuild()
    }
    return err
}

Prevention

When it happens

Trigger: gzip.NewReader(source) returns non-nil — unexpected EOF/gzip invalid header, because the tarball is truncated, corrupted on disk, or an HTML error page was saved instead of the archive.

Common situations: Earlier download silently wrote an error page (proxy portal) instead of the asset; tarball truncated by disk-full; file corrupted by a later writer; wrong file passed as tarballPath.

Understand the failure class

Background: "Invalid JSON response" and "Failed to parse response" errors: when an API answers 200 but the body isn't the JSON your library expected — this error's family across 28 libraries.

Related errors


AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/719e3f620165c460. Report an issue: GitHub.

Appendix: source

Thrown at go/cmd/bundler/main.go:1093

func extractCLILicense(tarballPath, outputPath string) error {
	outputDir := filepath.Dir(outputPath)
	if outputDir == "" {
		outputDir = "."
	}
	licensePath := licensePathForOutput(outputPath)
	if _, err := os.Stat(licensePath); err == nil {
		return nil
	}

	source, err := os.Open(tarballPath)
	if err != nil {
		return fmt.Errorf("failed to open release package: %w", err)
	}
	defer source.Close()

	gzReader, err := gzip.NewReader(source)
	if err != nil {
		return fmt.Errorf("failed to create gzip reader: %w", err)
	}
	defer gzReader.Close()

	tarReader := tar.NewReader(gzReader)
	for {
		header, err := tarReader.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return fmt.Errorf("failed to read tar: %w", err)
		}
		switch header.Name {
		case "package/LICENSE.md", "package/LICENSE":
			licenseName := filepath.Base(licensePath)
			if err := extractFileFromTarballStream(tarReader, outputDir, licenseName, os.FileMode(header.Mode)); err != nil {
				return fmt.Errorf("failed to write license: %w", err)
			}

View on GitHub (pinned to cd8cf15dc3)