{"record":{"id":"83290c0490a60375","repo":"plandex-ai/plandex","slug":"error-deleting-branch","errorCode":null,"errorMessage":"Error deleting branch: ","messagePattern":"Error deleting branch: ","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/handlers/branches.go","lineNumber":202,"sourceCode":"\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:   \"delete branch\",\n\t\tScope:    db.LockScopeWrite,\n\t\tCtx:      ctx,\n\t\tCancelFn: cancel,\n\t}, func(repo *db.GitRepo) error {\n\t\terr := repo.GitDeleteBranch(branch)\n\t\treturn err\n\t})\n\n\tif err != nil {\n\t\tlog.Printf(\"Error deleting branch: %v\\n\", err)\n\t\thttp.Error(w, \"Error deleting branch: \"+err.Error(), http.StatusInternalServerError)\n\t\treturn\n\t}\n\n\tlog.Println(\"Successfully deleted branch\")\n}\n","sourceCodeStart":184,"sourceCodeEnd":208,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/handlers/branches.go#L184-L208","documentation":"DeleteBranchHandler runs repo.GitDeleteBranch(branch) inside a write-locked repo operation and returns HTTP 500 'Error deleting branch: <err>' if the git deletion fails. This surfaces raw git errors (ref not found, lock contention, repo corruption) from the plan's underlying git repository.","triggerScenarios":"DELETE of a non-main branch when: the branch ref does not exist in the git repo (already deleted, or exists only in the DB), git fails due to a stale index.lock, the repo directory is missing/corrupted, or the write lock times out / context is cancelled.","commonSituations":"Deleting a branch that was already removed by another user/session (double delete); DB and git state out of sync after a failed prior operation; crashed server leaving .git lock files; disk full on the plans volume.","solutions":["Check the wrapped git error in the response/logs — 'not found' means the branch was already deleted and can be treated as success","Remove stale .git lock files in the plan's repo if present","Refresh the branch list and retry with an existing branch name","Verify repo storage health (disk space, git fsck) if corruption is suspected"],"exampleFix":"// before\nclient.DeleteBranch(planId, \"feature-x\") // may 500 if already gone\n// after\nbranches, _ := client.ListBranches(planId)\nif contains(branches, \"feature-x\") {\n    client.DeleteBranch(planId, \"feature-x\")\n}","handlingStrategy":"validation","validationCode":"// client: confirm branch still exists before deleting\nbranches, err := listBranches(planId)\nif err != nil { return err }\nif !slices.Contains(branches, branch) { return nil } // already gone — treat as success","typeGuard":"func branchExists(branches []Branch, name string) bool {\n    for _, b := range branches { if b.Name == name { return true } }\n    return false\n}","tryCatchPattern":"// idempotent delete: tolerate 'not found' in the 500 body\nif resp.StatusCode == http.StatusInternalServerError && strings.Contains(body, \"not found\") {\n    return nil // already deleted\n}","preventionTips":["Make deletes idempotent: treat already-deleted as success","Refresh the branch list immediately before deleting","Avoid concurrent deletes of the same branch from multiple sessions","Clean stale .git lock files after server crashes"],"tags":["git","http-500","branch","locking"],"backgroundTag":"git-branch-delete-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"}