{"record":{"id":"d3eccf3c4d4a312a","repo":"plandex-ai/plandex","slug":"error-getting-parent-branch","errorCode":null,"errorMessage":"Error getting parent branch: ","messagePattern":"Error getting parent branch: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/branches.go","lineNumber":121,"sourceCode":"\t\treturn\n\t}\n\tdefer func() {\n\t\tlog.Println(\"Closing request body\")\n\t\tr.Body.Close()\n\t}()\n\n\tvar req shared.CreateBranchRequest\n\tif err := json.Unmarshal(body, &req); err != nil {\n\t\tlog.Printf(\"Error parsing request body: %v\\n\", err)\n\t\thttp.Error(w, \"Error parsing request body \", http.StatusBadRequest)\n\t\treturn\n\t}\n\n\tparentBranch, err := db.GetDbBranch(planId, branch)\n\n\tif err != nil {\n\t\tlog.Printf(\"Error getting parent branch: %v\\n\", err)\n\t\thttp.Error(w, \"Error getting parent branch: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tctx, cancel := context.WithCancel(r.Context())\n\n\terr = db.ExecRepoOperation(db.ExecRepoOperationParams{\n\t\tOrgId:    auth.OrgId,\n\t\tUserId:   auth.User.Id,\n\t\tPlanId:   planId,\n\t\tBranch:   \"main\",\n\t\tReason:   \"create branch\",\n\t\tScope:    db.LockScopeWrite,\n\t\tCtx:      ctx,\n\t\tCancelFn: cancel,\n\t}, func(repo *db.GitRepo) error {\n\n\t\terr := db.WithTx(ctx, \"create branch\", func(tx *sqlx.Tx) error {\n\t\t\t_, err = db.CreateBranch(repo, plan, parentBranch, req.Name, tx)","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/branches.go#L103-L139","documentation":"After parsing the request, CreateBranchHandler fetches the parent branch record with db.GetDbBranch(planId, branch) (branch from the URL path) and returns HTTP 500 'Error getting parent branch: <err>' on failure. This resolves the DB row for the branch the new branch will fork from; failure means the lookup itself errored (DB issue) rather than the branch simply not existing.","triggerScenarios":"POST to create a branch whose parent path variable references a branch lookup that errors — database connectivity failure, query timeout, or a corrupted plans/branches table row; also context/tx issues inside GetDbBranch.","commonSituations":"Database temporarily unavailable or restarted; connection pool exhausted under load; planId/branch path variable malformed causing a query error; migrated schema where the branches table is missing or drifted.","solutions":["Check the server log for the wrapped error from GetDbBranch to distinguish DB connectivity from query errors","Verify the parent branch path variable is a valid existing branch name for the plan","Confirm the database is healthy and migrations are up to date","Retry after transient DB issues resolve"],"exampleFix":"// before\nparentBranch, err := db.GetDbBranch(planId, branch)\n// after\nparentBranch, err := db.GetDbBranch(planId, branch)\nif err != nil {\n    return fmt.Errorf(\"get parent branch %s for plan %s: %w\", branch, planId, err)\n}","handlingStrategy":"validation","validationCode":"// client: confirm parent branch exists before creating a child\nbranches, err := listBranches(planId)\nif err != nil { return err }\nif !slices.Contains(branches, parentBranch) {\n    return fmt.Errorf(\"parent branch %q does not exist\", parentBranch)\n}","typeGuard":null,"tryCatchPattern":"// distinguish transient DB errors for retry\nif resp.StatusCode == http.StatusInternalServerError && strings.Contains(body, \"sql:\") {\n    return retryWithBackoff(...)\n}","preventionTips":["Verify the parent branch exists via the list-branches endpoint first","Keep planId and branch path variables exact (no typos/whitespace)","Keep database migrations current","Retry once on transient DB errors before failing"],"tags":["database","http-500","branch","lookup"],"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-12T22:17:10.623Z"}