plandex-ai/plandex · error
Error creating branch:
Error message
Error creating branch:
What it means
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).
Source
Thrown at app/server/handlers/branches.go:153
CancelFn: cancel,
}, func(repo *db.GitRepo) error {
err := db.WithTx(ctx, "create branch", func(tx *sqlx.Tx) error {
_, err = db.CreateBranch(repo, plan, parentBranch, req.Name, tx)
if err != nil {
return fmt.Errorf("error creating branch: %v", err)
}
return nil
})
return err
})
if err != nil {
log.Printf("Error creating branch: %v\n", err)
http.Error(w, "Error creating branch: "+err.Error(), http.StatusInternalServerError)
return
}
log.Println("Successfully created branch")
}
func DeleteBranchHandler(w http.ResponseWriter, r *http.Request) {
log.Println("Received request for DeleteBranchHandler")
auth := Authenticate(w, r, true)
if auth == nil {
return
}
vars := mux.Vars(r)
planId := vars["planId"]
branch := vars["branch"]
View on GitHub (pinned to e2d772072e)
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
Example fix
// before
req := shared.CreateBranchRequest{Name: "main"} // may already exist
// after
branches, _ := client.ListBranches(planId)
if !contains(branches, "my-branch") {
req := shared.CreateBranchRequest{Name: "my-branch"}
_ = client.CreateBranch(planId, "main", req)
} Defensive patterns
Strategy: validation
Validate before calling
// client: check name uniqueness before creating
branches, _ := listBranches(planId)
if slices.Contains(branches, newName) {
return fmt.Errorf("branch %q already exists", newName)
}
if newName == "" || strings.ContainsAny(newName, " ~^:?*[\\") {
return errors.New("invalid branch name")
} Try / catch
// handle 500 with wrapped cause; treat 'already exists' as non-retryable
if resp.StatusCode == http.StatusInternalServerError {
if strings.Contains(respBody, "already exists") { return errConflict }
return retryWithBackoff(...)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error getting branches:
- error starting transaction: %v
- error removing expired locks: %v
- Error deleting branch:
- Error inviting user:
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/72dfdd48d6826cb0.
Report an issue: GitHub.