{"record":{"id":"480b38bb6df43a86","repo":"github/copilot-sdk","slug":"writing-license-file-w","errorCode":null,"errorMessage":"writing license file: %w","messagePattern":"writing license file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/internal/embeddedcli/embeddedcli.go","lineNumber":304,"sourceCode":"\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.\n\tif config.RuntimeLib != nil {\n\t\tlibPath, err := installRuntimeLib(installDir)\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/internal/embeddedcli/embeddedcli.go#L286-L322","documentation":"After installing the CLI binary, installAt writes config.License to finalPath+\".license\" via os.WriteFile. If that write fails, the error is wrapped as \"writing license file\". The binary itself is already installed; only the sidecar license file is missing.","triggerScenarios":"os.WriteFile(licensePath, config.License, 0644) fails because the install directory became unwritable, disk filled between the two writes, or a directory named finalPath+\".license\" exists at that path.","commonSituations":"Disk-full race between binary and license writes; security software blocking creation of the .license sidecar; a conflicting directory/file already named *.license.","solutions":["Check free disk space and directory write permissions","Remove any conflicting file or directory at finalPath+\".license\"","Re-run install after clearing the blocker — the binary does not need reinstalling if already correct","Verify no antivirus/EDR policy blocks creation of .license files"],"exampleFix":"// before\n// license write fails silently blocking install\n// after\nlicPath := finalPath + \".license\"\nif fi, err := os.Lstat(licPath); err == nil && fi.IsDir() {\n    os.RemoveAll(licPath) // clear conflicting entry before install\n}","handlingStrategy":"try-catch","validationCode":"licPath := finalPath + \".license\"\nif fi, err := os.Lstat(licPath); err == nil && fi.IsDir() {\n    os.RemoveAll(licPath)\n}\nif err := unix.Access(filepath.Dir(licPath), unix.W_OK); err != nil { return err }","typeGuard":null,"tryCatchPattern":"_, err := embeddedcli.Install(ctx, cfg)\nif err != nil && strings.Contains(err.Error(), \"writing license file\") {\n    return fmt.Errorf(\"license sidecar could not be written; check disk space and %s.lock conflicts\", finalPath)\n}","preventionTips":["Ensure no file/dir collides with the .license sidecar name","Keep sufficient free space (binary writes consume space moments earlier)","Whitelist sidecar file creation in security software policies"],"tags":["file-io","license","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"}