github/copilot-sdk · error

failed to extract binary

Error message

failed to extract binary: %w

What it means

io.Copy failed while writing the matched tar entry (the binary) to the output file, but outFile.Close() succeeded and its error is not included. This is the plain write/transfer failure path of extractFileFromTarball.

Solutions

  1. Re-download the artifact and validate its checksum before extraction
  2. Ensure sufficient free disk space on the destination volume
  3. Verify the tarball manually (tar -tzf) to confirm integrity
  4. Retry the extraction/installation
Defensive patterns

Strategy: validation

Validate before calling

if err := verifyChecksum(tarballPath, expectedSHA256); err != nil { return fmt.Errorf("corrupt tarball: %w", err) }
if free, err := diskFree(destDir); err == nil && free < minRequiredBytes { return fmt.Errorf("insufficient disk space") }

Try / catch

if err := extractFileFromTarball(tgz, destDir, target, out); err != nil {
    if strings.Contains(err.Error(), "failed to extract binary") && strings.Contains(err.Error(), "no space left") { return fmt.Errorf("disk full while installing; free space and retry") }
    return err
}

Prevention

When it happens

Trigger: extractFileFromTarball (from buildBundle, downloadCLIBinary, extractOptionalFileFromTarball) encounters a corrupt or truncated tar/gzip stream mid-entry, or a disk-full/ENOSPC write error while copying the binary payload.

Common situations: Corrupted release downloads on CI; full disks on runners; network-mounted output volumes dropping mid-write; truncated artifacts from interrupted downloads.

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 github/copilot-sdk@cd8cf15dc3 (2026-09-09). Data as JSON: /api/errors/2e022f4f0eb4599f. Report an issue: GitHub.

Appendix: source

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

		if err == io.EOF {
			break
		}
		if err != nil {
			return fmt.Errorf("failed to read tar: %w", err)
		}

		if header.Name == targetPath {
			outPath := filepath.Join(destDir, outputName)
			outFile, err := os.OpenFile(outPath, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, os.FileMode(header.Mode))
			if err != nil {
				return fmt.Errorf("failed to create output file: %w", err)
			}

			if _, err := io.Copy(outFile, tarReader); err != nil {
				if cerr := outFile.Close(); cerr != nil {
					return fmt.Errorf("failed to extract binary (copy error: %v, close error: %v)", err, cerr)
				}
				return fmt.Errorf("failed to extract binary: %w", err)
			}
			if err := outFile.Close(); err != nil {
				return fmt.Errorf("failed to close output file: %w", err)
			}
			return nil
		}
	}

	return fmt.Errorf("file %q not found in tarball", targetPath)
}

// extractOptionalFileFromTarball extracts a single file from a .tgz into destDir
// like extractFileFromTarball, but returns (false, nil) instead of an error when
// the file is absent. Used for the runtime library, which older CLI packages do
// not ship.
func extractOptionalFileFromTarball(tarballPath, destDir, targetPath, outputName string) (bool, error) {
	err := extractFileFromTarball(tarballPath, destDir, targetPath, outputName)
	if err == nil {

View on GitHub (pinned to cd8cf15dc3)