github/copilot-sdk · error
creating binary file
Error message
creating binary file: %w
What it means
installAt opens the destination file with os.OpenFile(finalPath, O_WRONLY|O_CREATE|O_TRUNC, 0755) to write the embedded CLI binary. If the open itself fails, the error is wrapped as "creating binary file". This typically means the path is unwritable or blocked.
Solutions
- Check parent directory exists and is writable by the current user (ls -ld, chmod/chown)
- Ensure finalPath is not a directory and no immutable/squashfs mount blocks writes
- Free disk space if the volume is full
- Run the installer with sufficient privileges or choose another installDir
Example fix
// before
installDir := "/usr/local/bin" // permission denied for non-root
// after
installDir := filepath.Join(os.Getenv("HOME"), ".local", "bin")
os.MkdirAll(installDir, 0o755) Defensive patterns
Strategy: validation
Validate before calling
dir := filepath.Dir(finalPath)
if fi, err := os.Stat(dir); err != nil || !fi.IsDir() { os.MkdirAll(dir, 0o755) }
if fi, err := os.Stat(finalPath); err == nil && fi.IsDir() { return errors.New("target is a directory") }
if err := unix.Access(dir, unix.W_OK); err != nil { return err } Try / catch
path, err := embeddedcli.Install(ctx, cfg)
if err != nil {
var pe *fs.PathError
if errors.As(err, &pe) && pe.Op == "open" {
return fmt.Errorf("cannot write %s: check permissions/space: %w", pe.Path, err)
}
return err
} Prevention
- Preflight write-permission on the install directory
- Choose user-writable install locations for non-elevated runs
- Monitor free disk space before large installs
When it happens
Trigger: os.OpenFile on finalPath fails: parent directory does not exist, permission denied, finalPath is a directory, disk full, or the path is on a read-only mount.
Common situations: Install directory created with wrong permissions; running as non-root where root is required; finalPath collides with an existing directory of the same name; container image with read-only filesystem.
Understand the failure class
Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.
Related errors
- failed to create output file
- writing binary file
- writing license file
- approveAll cannot be used when managed settings are enabled
- Permission handlers cannot return 'no-result' when…
AI-assisted analysis of github/copilot-sdk@cd8cf15dc3 (2026-09-09).
Data as JSON: /api/errors/78c02ef1158789ae.
Report an issue: GitHub.
Appendix: source
Thrown at go/internal/embeddedcli/embeddedcli.go:289
}
runtimePath = path
}
if config.RuntimeLib != nil {
libPath, err := installRuntimeLib(installDir)
if err != nil {
return "", err
}
runtimeLibPath = libPath
}
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)
}
}
View on GitHub (pinned to cd8cf15dc3)