{"record":{"id":"768f381b8c20adeb","repo":"github/copilot-sdk","slug":"hashing-existing-binary-w","errorCode":null,"errorMessage":"hashing existing binary: %w","messagePattern":"hashing existing binary: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/internal/embeddedcli/embeddedcli.go","lineNumber":262,"sourceCode":"\tif err := os.MkdirAll(installDir, 0755); err != nil {\n\t\treturn \"\", fmt.Errorf(\"creating install directory: %w\", err)\n\t}\n\n\t// Best effort to prevent concurrent installs.\n\tif release, _ := flock.Acquire(filepath.Join(installDir, \".copilot-cli.lock\")); release != nil {\n\t\tdefer release()\n\t}\n\n\tbinaryName := \"copilot\"\n\tif runtime.GOOS == \"windows\" {\n\t\tbinaryName += \".exe\"\n\t}\n\tfinalPath := filepath.Join(installDir, binaryName)\n\n\tif _, err := os.Stat(finalPath); err == nil {\n\t\texistingHash, err := hashFile(finalPath)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"hashing existing binary: %w\", err)\n\t\t}\n\t\tif !bytes.Equal(existingHash, config.CliHash) {\n\t\t\treturn \"\", fmt.Errorf(\"existing binary hash mismatch\")\n\t\t}\n\t\tif config.RuntimeExecutable != nil {\n\t\t\tpath, err := installRuntimePair(installDir)\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\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}","sourceCodeStart":244,"sourceCodeEnd":280,"githubUrl":"https://github.com/github/copilot-sdk/blob/cd8cf15dc3f9e762615790aaed0a771a0f392755/go/internal/embeddedcli/embeddedcli.go#L244-L280","documentation":"If a binary already exists at the target install path, installAt hashes it with hashFile to decide whether it matches the expected content. When hashing itself fails (e.g. permission denied reading the file, or the path is a directory), the error is wrapped with this message. This is distinct from the hash mismatch error that follows a successful hash.","triggerScenarios":"os.Stat reports the binary exists, but hashFile (which opens and reads the file) fails — unreadable permissions, file replaced by a directory/symlink to nowhere mid-check, or I/O error while reading.","commonSituations":"Another user's install left the binary mode 0600; a broken or malicious symlink at binaryName; antivirus or disk errors preventing reads; concurrent installs racing on the same path (the flock is best-effort and may not have been acquired).","solutions":["Check the wrapped error for the exact cause and fix file permissions (chmod/chown) so the file is readable","If the path is a broken symlink or directory, remove it and reinstall","Take the install lock or stop concurrent installers, then retry the install","As a last resort delete the versioned install dir and perform a clean install"],"exampleFix":"// before\n// failure: hashing existing binary: open .../copilot: permission denied\n// after\n$ sudo chmod a+r /path/to/install/<version>/copilot   # make existing binary readable\n$ # or remove and reinstall:\n$ rm -f /path/to/install/<version>/copilot && retry install","handlingStrategy":"retry","validationCode":"// ensure the existing binary is readable before install\nif fi, err := os.Stat(finalPath); err == nil {\n\tf, err := os.Open(finalPath); if err != nil { /* fix perms or remove */ } else { f.Close() }\n}","typeGuard":null,"tryCatchPattern":"// Go\npath, err := installAt(dir, version)\nif err != nil && strings.Contains(err.Error(), \"hashing existing binary\") {\n\t// remove the unreadable/stale file and retry once\n\tos.Remove(filepath.Join(dir, binaryName))\n\tpath, err = installAt(dir, version)\n}","preventionTips":["Run installs under one user with consistent file modes","Serialize installs with the provided flock to avoid races","Verify symlinks in install dirs resolve to regular files"],"tags":["filesystem","install","hashing"],"backgroundTag":"file-read-failed","analyzedSha":"cd8cf15dc3f9e762615790aaed0a771a0f392755","analyzedAt":"2026-09-09T18:32:31.973Z","contentChangedAt":"2026-09-09T18:32:31.973Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}