{"record":{"id":"edeeb88afdc85512","repo":"plandex-ai/plandex","slug":"error-getting-branches-v","errorCode":null,"errorMessage":"error getting branches: %v","messagePattern":"error getting branches: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/plans_crud.go","lineNumber":477,"sourceCode":"\t\tif err != nil {\n\t\t\terrCh <- fmt.Errorf(\"error getting recent model streams: %v\", err)\n\t\t\treturn\n\t\t}\n\t\terrCh <- nil\n\t}()\n\n\tgo func() {\n\t\tdefer func() {\n\t\t\tif r := recover(); r != nil {\n\t\t\t\tlog.Printf(\"panic in ListPlansRunningHandler: %v\\n%s\", r, debug.Stack())\n\t\t\t\terrCh <- fmt.Errorf(\"panic in ListPlansRunningHandler: %v\\n%s\", r, debug.Stack())\n\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t}\n\t\t}()\n\t\tvar err error\n\t\tbranches, err = db.ListBranchesForPlans(auth.OrgId, planIds)\n\t\tif err != nil {\n\t\t\terrCh <- fmt.Errorf(\"error getting branches: %v\", err)\n\t\t\treturn\n\t\t}\n\t\terrCh <- nil\n\t}()\n\n\tfor i := 0; i < 2; i++ {\n\t\terr := <-errCh\n\t\tif err != nil {\n\t\t\tlog.Println(err)\n\t\t\thttp.Error(w, err.Error(), http.StatusInternalServerError)\n\t\t\treturn\n\t\t}\n\t}\n\n\tres := shared.ListPlansRunningResponse{\n\t\tBranches:                   []*shared.Branch{},\n\t\tStreamStartedAtByBranchId:  map[string]time.Time{},\n\t\tStreamFinishedAtByBranchId: map[string]time.Time{},","sourceCodeStart":459,"sourceCodeEnd":495,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/plans_crud.go#L459-L495","documentation":"In ListPlansRunningHandler's second goroutine, db.ListBranchesForPlans(auth.OrgId, planIds) failed. The error is wrapped as 'error getting branches' and sent to errCh, resulting in HTTP 500. The DB layer returned an error executing the branch lookup for the org's plans.","triggerScenarios":"The ListBranchesForPlans query fails: DB unreachable, connection pool exhausted, invalid org ID, empty planIds producing a malformed SQL IN clause, or schema mismatch in the branches table.","commonSituations":"Database downtime or credential rotation; branches migration missing in the target environment; plan IDs referencing deleted rows under strict FK/permissions.","solutions":["Inspect the wrapped cause to identify the DB-level failure.","Confirm DB connectivity and credentials for the server process.","Verify the branches schema/migration is applied and orgId/planIds values are valid.","Check Postgres logs for the failing statement."],"exampleFix":"// before\nbranches, err = db.ListBranchesForPlans(auth.OrgId, planIds)\n// after\nbranches, err = db.ListBranchesForPlans(auth.OrgId, planIds)\nif err != nil {\n    log.Printf(\"ListBranchesForPlans org=%s plans=%v: %v\", auth.OrgId, planIds, err)\n}","handlingStrategy":"try-catch","validationCode":"// Go\nif auth.OrgId == \"\" {\n    http.Error(w, \"missing org id\", http.StatusBadRequest)\n    return\n}","typeGuard":"func branchesQueryable(orgId string, planIds []string) bool { return orgId != \"\" && len(planIds) > 0 }","tryCatchPattern":"branches, err := db.ListBranchesForPlans(auth.OrgId, planIds)\nif err != nil {\n    log.Printf(\"branches query failed: %v\", err)\n    http.Error(w, \"failed to load branches\", http.StatusInternalServerError)\n    return\n}","preventionTips":["Verify org and plan IDs are valid before querying.","Keep branch-table migrations in sync across environments.","Monitor DB health; surface wrapped causes in logs.","Retry transient DB errors with backoff."],"tags":["database","go","postgres"],"backgroundTag":"database-query-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}