{"record":{"id":"78c02ef1158789ae","repo":"github/copilot-sdk","slug":"creating-binary-file-w","errorCode":null,"errorMessage":"creating binary file: %w","messagePattern":"creating binary file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/internal/embeddedcli/embeddedcli.go","lineNumber":289,"sourceCode":"\t\t\t}\n\t\t\truntimePath = path\n\t\t}\n\t\tif config.RuntimeLib != nil {\n\t\t\tlibPath, err := installRuntimeLib(installDir)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t\truntimeLibPath = libPath\n\t\t}\n\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","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/internal/embeddedcli/embeddedcli.go#L271-L307","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ninstallDir := \"/usr/local/bin\" // permission denied for non-root\n// after\ninstallDir := filepath.Join(os.Getenv(\"HOME\"), \".local\", \"bin\")\nos.MkdirAll(installDir, 0o755)","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(finalPath)\nif fi, err := os.Stat(dir); err != nil || !fi.IsDir() { os.MkdirAll(dir, 0o755) }\nif fi, err := os.Stat(finalPath); err == nil && fi.IsDir() { return errors.New(\"target is a directory\") }\nif err := unix.Access(dir, unix.W_OK); err != nil { return err }","typeGuard":null,"tryCatchPattern":"path, err := embeddedcli.Install(ctx, cfg)\nif err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && pe.Op == \"open\" {\n        return fmt.Errorf(\"cannot write %s: check permissions/space: %w\", pe.Path, err)\n    }\n    return err\n}","preventionTips":["Preflight write-permission on the install directory","Choose user-writable install locations for non-elevated runs","Monitor free disk space before large installs"],"tags":["file-io","permissions","installation"],"backgroundTag":"file-open-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"}