{"record":{"id":"5802e2a9916f5076","repo":"gastownhall/beads","slug":"list-branches-w","errorCode":null,"errorMessage":"list branches: %w","messagePattern":"list branches: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/branches.go","lineNumber":12,"sourceCode":"package versioncontrolops\n\nimport (\n\t\"context\"\n\t\"fmt\"\n)\n\n// ListBranches returns the names of all Dolt branches, sorted by name.\nfunc ListBranches(ctx context.Context, db DBConn) ([]string, error) {\n\trows, err := db.QueryContext(ctx, \"SELECT name FROM dolt_branches ORDER BY name\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"list branches: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tvar branches []string\n\tfor rows.Next() {\n\t\tvar name string\n\t\tif err := rows.Scan(&name); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"scan branch: %w\", err)\n\t\t}\n\t\tbranches = append(branches, name)\n\t}\n\treturn branches, rows.Err()\n}\n\n// CurrentBranch returns the name of the active branch.\nfunc CurrentBranch(ctx context.Context, db DBConn) (string, error) {\n\tvar branch string\n\tif err := db.QueryRowContext(ctx, \"SELECT active_branch()\").Scan(&branch); err != nil {","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/branches.go#L1-L30","documentation":"ListBranches queries `SELECT name FROM dolt_branches ORDER BY name` and wraps query failure as \"list branches: <cause>\". It throws when the query cannot be executed — the dolt_branches system table is unavailable, the connection is broken, or the target is not a Dolt database. This is the first step of the function, so no partial data is returned.","triggerScenarios":"ListBranches(ctx, db) when db.QueryContext fails: connection error, database not a Dolt DB (no dolt_branches table), wrong database selected, or server version lacking the table.","commonSituations":"Pointing the connection at a non-Dolt MySQL database; calling before selecting/creating a database on the server; network drop; Dolt version too old for dolt_branches.","solutions":["Confirm the connection targets a Dolt database with dolt_branches available (SELECT 1 FROM dolt_branches LIMIT 1)","Ensure a database is in use (USE db / connection DSN dbname) before listing","Inspect the wrapped cause to separate connectivity from schema issues","Retry transient connection errors"],"exampleFix":"// before\nbranches, err := vcops.ListBranches(ctx, db)\n// after\nif err := db.PingContext(ctx); err != nil { return fmt.Errorf(\"db down: %w\", err) }\nbranches, err := vcops.ListBranches(ctx, db)\nif err != nil { return fmt.Errorf(\"branches: %w\", err) }","handlingStrategy":"validation","validationCode":"var one int\nif err := db.QueryRowContext(ctx, \"SELECT 1 FROM dolt_branches LIMIT 1\").Scan(&one); err != nil {\n\treturn fmt.Errorf(\"not a dolt database: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"branches, err := vcops.ListBranches(ctx, db)\nif err != nil {\n\tif strings.Contains(err.Error(), \"list branches\") && errors.Is(errors.Unwrap(err), sql.ErrConnDone) {\n\t\treturn reconnectAndRetry()\n\t}\n\treturn err\n}","preventionTips":["Verify the DSN points at a Dolt database with a database selected","Check Dolt server version supports dolt_branches","Ping before batch operations that list branches"],"tags":["dolt","branches","sql","query"],"backgroundTag":"dolt-system-table-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}