{"record":{"id":"dce053c541a50fc2","repo":"gastownhall/beads","slug":"cannot-read-cmd-bd-version-go-v","errorCode":null,"errorMessage":"cannot read cmd/bd/version.go: %v","messagePattern":"cannot read cmd/bd/version\\.go: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/preflight.go","lineNumber":828,"sourceCode":"\t\trestored = true\n\t\treturn false, oldHash, newHash, nil\n\t}\n\n\tupdated := append(append([]byte{}, content[:loc[4]]...), append([]byte(newHash), content[loc[5]:]...)...)\n\tif err := os.WriteFile(nixPath, updated, nixPerm); err != nil {\n\t\treturn false, oldHash, newHash, fmt.Errorf(\"cannot update default.nix: %v\", err)\n\t}\n\trestored = true\n\treturn true, oldHash, newHash, nil\n}\n\n// fixVersionSync updates cmd/bd/version.go to match the version in default.nix.\n// default.nix is the source of truth. Returns (fixed, oldVersion, newVersion, err).\nfunc fixVersionSync() (bool, string, string, error) {\n\tvgoPath := \"cmd/bd/version.go\"\n\tvgoInfo, err := os.Stat(vgoPath)\n\tif err != nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"cannot read cmd/bd/version.go: %v\", err)\n\t}\n\tvgoPerm := vgoInfo.Mode().Perm()\n\n\tvgoContent, err := os.ReadFile(vgoPath)\n\tif err != nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"cannot read cmd/bd/version.go: %v\", err)\n\t}\n\n\tvgoRe := regexp.MustCompile(`(Version\\s*=\\s*)\"([^\"]+)\"`)\n\tvgoLoc := vgoRe.FindSubmatchIndex(vgoContent)\n\tif vgoLoc == nil {\n\t\treturn false, \"\", \"\", fmt.Errorf(\"cannot parse Version from cmd/bd/version.go\")\n\t}\n\toldVersion := string(vgoContent[vgoLoc[4]:vgoLoc[5]])\n\n\tnixContent, err := os.ReadFile(\"default.nix\")\n\tif err != nil {\n\t\t// No default.nix — nothing to sync against","sourceCodeStart":810,"sourceCodeEnd":846,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/preflight.go#L810-L846","documentation":"fixVersionSync keeps cmd/bd/version.go's Version constant in sync with the version in default.nix (default.nix is the source of truth). Its first step os.Stat's cmd/bd/version.go to capture permissions; if the stat fails the file is treated as unreadable and this error (with the message 'cannot read') wraps the os error.","triggerScenarios":"Running `bd fix` from a directory where cmd/bd/version.go does not exist at that relative path (not at repo root), the path is a broken symlink, or directory permissions prevent stat.","commonSituations":"Executing `bd fix` from a subdirectory (e.g. cmd/bd itself) so the relative path cmd/bd/version.go doesn't resolve; version.go renamed or removed during refactors; broken symlink in a copied workspace.","solutions":["Run `bd fix` from the repository root so the relative path cmd/bd/version.go resolves","Verify the file exists: `ls cmd/bd/version.go`; restore from git if deleted (`git checkout -- cmd/bd/version.go`)","Fix directory traversal permissions if the repo tree is not readable by the current user"],"exampleFix":"// before\n$ cd cmd/bd && bd fix\ncannot read cmd/bd/version.go: stat cmd/bd/version.go: no such file or directory\n// after\n$ cd /path/to/repo && bd fix","handlingStrategy":"validation","validationCode":"[ -f cmd/bd/version.go ] || { echo \"run from repo root; cmd/bd/version.go missing\"; exit 1; }","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"bd\", \"fix\").CombinedOutput()\nif err != nil && strings.Contains(string(out), \"cannot read cmd/bd/version.go\") {\n    // cd to repo root or restore version.go, then retry\n}","preventionTips":["Run bd fix only from the repository root","Keep cmd/bd/version.go tracked in git","Avoid renaming/removing version.go without updating fix tooling"],"tags":["filesystem","file-not-found","versioning","cli"],"backgroundTag":"file-not-found","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}