{"record":{"id":"58ef210e75d9ebf1","repo":"gastownhall/beads","slug":"delete-branch-s-w","errorCode":null,"errorMessage":"delete branch %s: %w","messagePattern":"delete branch (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"internal/storage/versioncontrolops/branches.go","lineNumber":47,"sourceCode":"\tvar branch string\n\tif err := db.QueryRowContext(ctx, \"SELECT active_branch()\").Scan(&branch); err != nil {\n\t\treturn \"\", fmt.Errorf(\"get current branch: %w\", err)\n\t}\n\treturn branch, nil\n}\n\n// CreateBranch creates a new Dolt branch from the current HEAD.\nfunc CreateBranch(ctx context.Context, db DBConn, name string) error {\n\tif _, err := db.ExecContext(ctx, \"CALL DOLT_BRANCH(?)\", name); err != nil {\n\t\treturn fmt.Errorf(\"create branch %s: %w\", name, err)\n\t}\n\treturn nil\n}\n\n// DeleteBranch force-deletes a Dolt branch.\nfunc DeleteBranch(ctx context.Context, db DBConn, name string) error {\n\tif _, err := db.ExecContext(ctx, \"CALL DOLT_BRANCH('-D', ?)\", name); err != nil {\n\t\treturn fmt.Errorf(\"delete branch %s: %w\", name, err)\n\t}\n\treturn nil\n}\n\n// CheckoutBranch switches the active session to the named branch.\nfunc CheckoutBranch(ctx context.Context, db DBConn, name string) error {\n\tif _, err := db.ExecContext(ctx, \"CALL DOLT_CHECKOUT(?)\", name); err != nil {\n\t\treturn fmt.Errorf(\"checkout branch %s: %w\", name, err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":29,"sourceCodeEnd":59,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/branches.go#L29-L59","documentation":"DeleteBranch runs CALL DOLT_BRANCH('-D', ?) to force-delete a branch and wraps failures as 'delete branch <name>: %w'. Dolt errors when the branch does not exist or cannot be deleted (e.g. it is the current branch). The wrapped driver error preserves Dolt's specific message.","triggerScenarios":"Calling DeleteBranch on a branch name that doesn't exist; attempting to delete the currently checked-out branch; the delete call failing due to connection problems.","commonSituations":"Best-effort cleanup code deleting an already-deleted temp branch (e.g. compact-tmp deleted twice); trying to delete 'main' while checked out on it; typo in branch name.","solutions":["Treat 'branch not found' from the wrapped error as success (idempotent delete) rather than a failure","Checkout another branch (e.g. main) before deleting the current branch","Verify the branch exists with a dolt_branches query before deleting"],"exampleFix":"// before\nerr := versioncontrolops.DeleteBranch(ctx, db, \"compact-tmp\")\n// after\nerr := versioncontrolops.DeleteBranch(ctx, db, \"compact-tmp\")\nif err != nil && !strings.Contains(err.Error(), \"not found\") {\n    return err\n}","handlingStrategy":"try-catch","validationCode":"var count int\n_ = db.QueryRowContext(ctx,\n    \"SELECT COUNT(*) FROM dolt_branches WHERE name = ?\", name).Scan(&count)\n// count == 0 → already deleted, skip","typeGuard":null,"tryCatchPattern":"err := versioncontrolops.DeleteBranch(ctx, db, name)\nif err != nil {\n    if strings.Contains(err.Error(), \"not found\") || strings.Contains(err.Error(), \"unknown branch\") {\n        return nil // idempotent delete\n    }\n    return err\n}","preventionTips":["Treat missing-branch deletes as no-ops","Never delete the currently checked-out branch; checkout main first","Track which branches your code creates so cleanup is accurate","Use force-delete (-D is already used) only on non-current branches"],"tags":["dolt","sql","branch","cleanup"],"backgroundTag":"dolt-branch-operation-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}