{"record":{"id":"d8eed1103cb59a2d","repo":"gastownhall/beads","slug":"get-status-w","errorCode":null,"errorMessage":"get status: %w","messagePattern":"get status: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/versioncontrolops/version_control.go","lineNumber":20,"sourceCode":"\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"regexp\"\n\t\"strings\"\n\n\t\"github.com/steveyegge/beads/internal/storage\"\n\t\"github.com/steveyegge/beads/internal/storage/issueops\"\n)\n\n// validTablePattern matches valid SQL table names (letters, digits, underscores).\nvar validTablePattern = regexp.MustCompile(`^[a-zA-Z_][a-zA-Z0-9_]*$`)\n\n// Status returns the current Dolt working set status (staged and unstaged changes).\nfunc Status(ctx context.Context, db DBConn) (*storage.Status, error) {\n\trows, err := db.QueryContext(ctx, \"SELECT table_name, staged, status FROM dolt_status\")\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"get status: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tstatus := &storage.Status{\n\t\tStaged:   make([]storage.StatusEntry, 0),\n\t\tUnstaged: make([]storage.StatusEntry, 0),\n\t}\n\n\tfor rows.Next() {\n\t\tvar tableName string\n\t\tvar staged bool\n\t\tvar statusStr string\n\t\tif err := rows.Scan(&tableName, &staged, &statusStr); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"scan status: %w\", err)\n\t\t}\n\t\tentry := storage.StatusEntry{Table: tableName, Status: statusStr}\n\t\tif staged {\n\t\t\tstatus.Staged = append(status.Staged, entry)","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/versioncontrolops/version_control.go#L2-L38","documentation":"Status wraps a failed query \"SELECT table_name, staged, status FROM dolt_status\" as \"get status: <underlying>\". The library throws it because reading the Dolt working set (the dolt_status system table) failed at the SQL level before any rows were scanned. Typically the database is not a Dolt database, the working set is unreadable, or the underlying connection/context failed.","triggerScenarios":"Calling Status against a database that lacks the dolt_status table (non-Dolt or not a Dolt-initialized schema); the Dolt engine cannot read the working set (corrupt repo_state / working-set file); the context is cancelled or the connection drops mid-query.","commonSituations":"Pointing bd at a plain MySQL/Dolt-SQL-server database that was never dolt-initialized; running status while another process holds a corrupted working set; stale connection after the embedded engine restarted.","solutions":["Verify the target database is Dolt-initialized (dolt_status exists) — run any Dolt query like SELECT 1 FROM dolt_status LIMIT 1 to confirm.","If the working set is corrupt, run the engine's repair path (re-init Dolt in that directory or restore repo_state.json from a backup).","Check connection health and retry; cancel/timeout of ctx produces this too.","Inspect the wrapped error message for driver-specific causes (unknown table vs. connection refused) and fix accordingly."],"exampleFix":"// before\nrows, err := db.QueryContext(ctx, \"SELECT table_name, staged, status FROM dolt_status\") // plain MySQL db, no dolt_status\n// after\n// initialize the db as a Dolt database first:\n// dolt init  (or ensure the embedded engine opened a dolt-initialized directory)\nrows, err := db.QueryContext(ctx, \"SELECT table_name, staged, status FROM dolt_status\")","handlingStrategy":"type-guard","validationCode":"// confirm the target is a Dolt database before calling Status\nif _, err := db.QueryContext(ctx, \"SELECT 1 FROM dolt_status LIMIT 1\"); err != nil {\n    return fmt.Errorf(\"not a Dolt-initialized database: %w\", err)\n}","typeGuard":"func isDoltReady(ctx context.Context, db DBConn) bool {\n    rows, err := db.QueryContext(ctx, \"SELECT 1 FROM dolt_status LIMIT 1\")\n    if err != nil { return false }\n    rows.Close()\n    return true\n}","tryCatchPattern":"st, err := versioncontrolops.Status(ctx, db)\nif err != nil {\n    if strings.Contains(err.Error(), \"get status\") && strings.Contains(err.Error(), \"dolt_status\") {\n        return fmt.Errorf(\"database is not Dolt-initialized: %w\", err)\n    }\n    if errors.Is(err, context.DeadlineExceeded) { return retryLater }\n    return err\n}","preventionTips":["Never point bd at a plain MySQL schema; ensure the directory was dolt-initialized.","Check connection health (ping) before status calls after an engine restart.","Set sane ctx deadlines so cancellations surface as timeouts, not half-read states.","If dolt_status becomes unreadable, suspect a corrupt working set and restore repo_state.json from backup rather than retrying blindly."],"tags":["dolt","sql","status","query"],"backgroundTag":"unknown-sql-table","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}