{"record":{"id":"3539eb10ce04d47b","repo":"github/copilot-sdk","slug":"writing-binary-file-w","errorCode":null,"errorMessage":"writing binary file: %w","messagePattern":"writing binary file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/internal/embeddedcli/embeddedcli.go","lineNumber":299,"sourceCode":"\t\tif err := installRuntimeAssets(installDir); err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\treturn finalPath, nil\n\t}\n\n\tf, err := os.OpenFile(finalPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"creating binary file: %w\", err)\n\t}\n\t_, err = io.Copy(f, config.Cli)\n\tif err1 := f.Close(); err1 != nil && err == nil {\n\t\terr = err1\n\t}\n\tif closer, ok := config.Cli.(io.Closer); ok {\n\t\tcloser.Close()\n\t}\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"writing binary file: %w\", err)\n\t}\n\tif len(config.License) > 0 {\n\t\tlicensePath := finalPath + \".license\"\n\t\tif err := os.WriteFile(licensePath, config.License, 0644); err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"writing license file: %w\", err)\n\t\t}\n\t}\n\n\tif config.RuntimeExecutable != nil {\n\t\tpath, err := installRuntimePair(installDir)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\t\truntimePath = path\n\t}\n\n\t// Install the native in-process runtime library (if bundled) next to the CLI.\n\t// Fail closed on any hash mismatch; never place unverified native code.","sourceCodeStart":281,"sourceCodeEnd":317,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/internal/embeddedcli/embeddedcli.go#L281-L317","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nf, _ := os.OpenFile(finalPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)\nio.Copy(f, cfg.Cli) // fails: writing binary file: no space left on device\n// after\nif err := checkFreeSpace(installDir, cfg.CliSize); err != nil { return err } // preflight\nif _, err := io.Copy(f, cfg.Cli); err != nil { os.Remove(finalPath); return err }","handlingStrategy":"try-catch","validationCode":"var avail uint64\nif st, err := os.Stat(installDir); err == nil {\n    if ok, _ := checkFreeSpace(st, expectedSize); !ok { return errors.New(\"insufficient disk space\") }\n}","typeGuard":null,"tryCatchPattern":"path, err := embeddedcli.Install(ctx, cfg)\nif err != nil && strings.Contains(err.Error(), \"writing binary file\") {\n    os.Remove(path) // clean partial write\n    return fmt.Errorf(\"install failed mid-write (disk full?): %w\", err)\n}","preventionTips":["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"],"tags":["file-io","disk","installation"],"backgroundTag":"file-write-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}