github/copilot-sdk · error
writing binary file
Error message
writing binary file: %w
What it means
After successfully creating the destination file, installAt copies the embedded CLI stream into it with io.Copy. If that copy (or the deferred close) fails, the error is wrapped as "writing binary file". The binary on disk may be truncated or empty at this point.
Solutions
- Check free disk space and quotas on the install volume
- Verify the source of config.Cli is intact (hash its content before install)
- Remove the partially written finalPath and retry the install
- Retry after transient I/O failure; investigate storage health if persistent
Example fix
// before
f, _ := os.OpenFile(finalPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
io.Copy(f, cfg.Cli) // fails: writing binary file: no space left on device
// after
if err := checkFreeSpace(installDir, cfg.CliSize); err != nil { return err } // preflight
if _, err := io.Copy(f, cfg.Cli); err != nil { os.Remove(finalPath); return err } Defensive patterns
Strategy: try-catch
Validate before calling
var avail uint64
if st, err := os.Stat(installDir); err == nil {
if ok, _ := checkFreeSpace(st, expectedSize); !ok { return errors.New("insufficient disk space") }
} Try / catch
path, err := embeddedcli.Install(ctx, cfg)
if err != nil && strings.Contains(err.Error(), "writing binary file") {
os.Remove(path) // clean partial write
return fmt.Errorf("install failed mid-write (disk full?): %w", err)
} Prevention
- Check disk space/quotas before install
- Delete partial outputs on failure (the library may leave a truncated file)
- Keep embedded assets verified by hash before install
When it happens
Trigger: io.Copy(f, config.Cli) or f.Close() returns an error: disk-full mid-write, source reader (config.Cli) returns a read error, or close-time flush fails.
Common situations: Disk quota exceeded mid-install; the embedded CLI reader came from a truncated or corrupt embedded asset; network-backed source (e.g. HTTP body) interrupted.
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
- creating binary file
- writing license file
- ELF probe too small: + size + bytes
- Program header table offset outside probe window: + phoff
- PT_INTERP extends past probe window; increase probe size
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/3539eb10ce04d47b.
Report an issue: GitHub.
Appendix: source
Thrown at go/internal/embeddedcli/embeddedcli.go:299
if err := installRuntimeAssets(installDir); err != nil {
return "", err
}
return finalPath, nil
}
f, err := os.OpenFile(finalPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
if err != nil {
return "", fmt.Errorf("creating binary file: %w", err)
}
_, err = io.Copy(f, config.Cli)
if err1 := f.Close(); err1 != nil && err == nil {
err = err1
}
if closer, ok := config.Cli.(io.Closer); ok {
closer.Close()
}
if err != nil {
return "", fmt.Errorf("writing binary file: %w", err)
}
if len(config.License) > 0 {
licensePath := finalPath + ".license"
if err := os.WriteFile(licensePath, config.License, 0644); err != nil {
return "", fmt.Errorf("writing license file: %w", err)
}
}
if config.RuntimeExecutable != nil {
path, err := installRuntimePair(installDir)
if err != nil {
return "", err
}
runtimePath = path
}
// Install the native in-process runtime library (if bundled) next to the CLI.
// Fail closed on any hash mismatch; never place unverified native code.View on GitHub (pinned to cd8cf15dc3)