plandex-ai/plandex · error
error creating branch: %v
Error message
error creating branch: %v
What it means
Wraps a failure from db.CreateBranch inside the 'create branch' transaction. The branch could not be created for the given repo/plan/parent — e.g. duplicate name, missing parent, or DB constraint failure — causing the whole WithTx block to roll back.
Source
Thrown at app/server/handlers/branches.go:142
ctx, cancel := context.WithCancel(r.Context())
err = db.ExecRepoOperation(db.ExecRepoOperationParams{
OrgId: auth.OrgId,
UserId: auth.User.Id,
PlanId: planId,
Branch: "main",
Reason: "create branch",
Scope: db.LockScopeWrite,
Ctx: ctx,
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) {View on GitHub (pinned to e2d772072e)
Solutions
- Check the wrapped %v cause — most often a duplicate-name constraint violation
- Use a unique branch name or verify the branch does not already exist
- Confirm parentBranch still exists and is accessible in this repo
- Retry if the error was transient (deadlock/connection) — WithTx rolls back cleanly
Example fix
// before
_, err = db.CreateBranch(repo, plan, parentBranch, req.Name, tx)
if err != nil {
return fmt.Errorf("error creating branch: %v", err)
}
// after
_, err = db.CreateBranch(repo, plan, parentBranch, req.Name, tx)
if err != nil {
if strings.Contains(err.Error(), "duplicate" ) {
return fmt.Errorf("branch %q already exists", req.Name)
}
return fmt.Errorf("error creating branch: %v", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
// pre-check before the transaction
exists, _ := db.BranchExists(repo, req.Name)
if exists {
return fmt.Errorf("branch %q already exists", req.Name)
} Try / catch
err := CreateBranchHandler(w, r, req)
if err != nil && strings.Contains(err.Error(), "error creating branch") {
if strings.Contains(err.Error(), "duplicate") || strings.Contains(err.Error(), "unique") {
http.Error(w, "branch name already in use", http.StatusConflict)
return
}
http.Error(w, err.Error(), http.StatusInternalServerError)
} Prevention
- Uniqueness-check branch names client-side before submit
- Validate parent branch existence before invoking creation
- Classify constraint violations as 409 vs transient errors as retryable 5xx
- Rely on WithTx rollback so failed creates leave no partial state
When it happens
Trigger: Branch creation API runs the WithTx callback; CreateBranch returns an error such as a unique-constraint violation on branch name, invalid parentBranch reference, or underlying SQL error.
Common situations: Client tries to create a branch whose name already exists; parent branch deleted or renamed concurrently; DB connectivity issue mid-transaction; name violates constraints (length/charset).
Related errors
- error creating invite: %v
- error deleting invite: %v
- error accepting invite: %v
- error creating org user: %v
- error starting transaction: %v
AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05).
Data as JSON: /api/errors/74ad0a0d9aee49d5.
Report an issue: GitHub.