{"record":{"id":"72dfdd48d6826cb0","repo":"plandex-ai/plandex","slug":"error-creating-branch","errorCode":null,"errorMessage":"Error creating branch: ","messagePattern":"Error creating branch: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/branches.go","lineNumber":153,"sourceCode":"\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)\n\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error creating branch: %v\", err)\n\t\t\t}\n\n\t\t\treturn nil\n\t\t})\n\n\t\treturn err\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error creating branch: %v\\n\", err)\n\t\thttp.Error(w, \"Error creating branch: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully created branch\")\n}\n\nfunc DeleteBranchHandler(w http.ResponseWriter, r *http.Request) {\n\tlog.Println(\"Received request for DeleteBranchHandler\")\n\n\tauth := Authenticate(w, r, true)\n\tif auth == nil {\n\t\treturn\n\t}\n\n\tvars := mux.Vars(r)\n\tplanId := vars[\"planId\"]\n\tbranch := vars[\"branch\"]\n","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/branches.go#L135-L171","documentation":"CreateBranchHandler executes the actual branch creation inside a transaction (db.WithTx -> db.CreateBranch) under a write-locked repo operation, and returns HTTP 500 'Error creating branch: <err>' if any step fails. The inner code already wraps errors as 'error creating branch: %v', so the response contains the nested cause (git operation, insert, or lock failure).","triggerScenarios":"POST creating a branch when: the branch name already exists (git ref or DB unique constraint), the git repo write operation fails, the DB transaction fails/rolls back, or the write lock on 'main' can't be acquired / context cancelled mid-operation.","commonSituations":"Attempting to create a branch name that already exists on the plan; concurrent branch creation racing on the same name; repo storage full or git lock file (index.lock) left behind from a crash; DB constraint violation after schema changes.","solutions":["Check the wrapped error in the 500 body/logs — 'already exists' means pick a different branch name","Ensure no stale git lock files (repo/.git/index.lock) remain from a crashed operation","Retry if the write lock was contended by another in-flight plan operation","Verify disk space on the plans volume if git write operations fail"],"exampleFix":"// before\nreq := shared.CreateBranchRequest{Name: \"main\"} // may already exist\n// after\nbranches, _ := client.ListBranches(planId)\nif !contains(branches, \"my-branch\") {\n    req := shared.CreateBranchRequest{Name: \"my-branch\"}\n    _ = client.CreateBranch(planId, \"main\", req)\n}","handlingStrategy":"validation","validationCode":"// client: check name uniqueness before creating\nbranches, _ := listBranches(planId)\nif slices.Contains(branches, newName) {\n    return fmt.Errorf(\"branch %q already exists\", newName)\n}\nif newName == \"\" || strings.ContainsAny(newName, \" ~^:?*[\\\\\") {\n    return errors.New(\"invalid branch name\")\n}","typeGuard":null,"tryCatchPattern":"// handle 500 with wrapped cause; treat 'already exists' as non-retryable\nif resp.StatusCode == http.StatusInternalServerError {\n    if strings.Contains(respBody, \"already exists\") { return errConflict }\n    return retryWithBackoff(...)\n}","preventionTips":["Generate unique branch names (suffix with timestamp) for automation","Serialize branch-creation calls per plan; don't create the same name concurrently","Clean up stale git lock files after crashes","Monitor disk space on the plans volume"],"tags":["git","database","transaction","http-500","locking"],"backgroundTag":"git-repo-operation-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"}