github/copilot-sdk · error
failed to extract binary
Error message
failed to extract binary (copy error: %v, close error: %v)
What it means
While copying the matched tar entry into the output file, io.Copy failed and the attempted outFile.Close() also returned an error. Both errors are reported in one message (copy error first, then close error) since the primary root cause must not be masked.
Solutions
- Re-download the tarball and verify its checksum
- Free disk space or raise quota on the destination volume
- Address the close error cause reported in the second half of the message
- Retry the extraction on a healthy filesystem
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(), "copy error") { log.Printf("copy+close failure on %s: %v", tgz, err) }
return err
} Prevention
- Validate checksums before extraction
- Reserve sufficient disk space for extracted binaries
- Avoid installing onto network volumes in CI
- Re-download artifacts rather than retrying corrupt ones
When it happens
Trigger: extractFileFromTarball (from buildBundle, downloadCLIBinary, extractOptionalFileFromTarball) hits a corrupt/truncated tar stream mid-entry or a disk-full/read-only write failure, and closing the partially written file also fails.
Common situations: Interrupted downloads producing truncated archives; full disk while installing a large CLI binary; failing storage volumes; quota limits on CI runners.
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
- failed to extract license: copy error
- failed to extract license
- failed to extract binary
- failed to create gzip reader
- failed to read tar
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/c33e0f9257cf9c24.
Report an issue: GitHub.
Appendix: source
Thrown at go/cmd/bundler/main.go:1183
for {
header, err := tarReader.Next()
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) {View on GitHub (pinned to cd8cf15dc3)