gastownhall/beads · error
failed to count issues: %w
Error message
failed to count issues: %w
What it means
runDoltDiagnosticQueries runs 'SELECT COUNT(*) FROM issues' to populate TotalIssues; if that query fails the error is wrapped as 'failed to count issues'. Subsequent open-issue count failures are tolerated (-1), so this first query is the hard gate — usually schema or connectivity problems.
Source
Thrown at cmd/bd/doctor/perf_dolt.go:158
db.SetMaxOpenConns(5)
db.SetMaxIdleConns(2)
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
if err := db.PingContext(ctx); err != nil {
return fmt.Errorf("failed to ping server: %w", err)
}
metrics.ConnectionTime = time.Since(start).Milliseconds()
// Run all diagnostics
return runDoltDiagnosticQueries(ctx, db, metrics)
}
// runDoltDiagnosticQueries runs the diagnostic queries and populates metrics
func runDoltDiagnosticQueries(ctx context.Context, db *sql.DB, metrics *DoltPerfMetrics) error {
// Get issue counts
if err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM issues").Scan(&metrics.TotalIssues); err != nil {
return fmt.Errorf("failed to count issues: %w", err)
}
if err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM issues WHERE status != 'closed'").Scan(&metrics.OpenIssues); err != nil {
metrics.OpenIssues = -1 // Mark as unavailable
}
if err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM issues WHERE status = 'closed'").Scan(&metrics.ClosedIssues); err != nil {
metrics.ClosedIssues = -1
}
if err := db.QueryRowContext(ctx, "SELECT COUNT(*) FROM dependencies").Scan(&metrics.Dependencies); err != nil {
metrics.Dependencies = -1
}
// Try to get Dolt version
if err := db.QueryRowContext(ctx, "SELECT dolt_version()").Scan(&metrics.DoltVersion); err != nil {
metrics.DoltVersion = "unknown"
}View on GitHub (pinned to 71377f2769)
Solutions
- Verify the database name in the DSN matches the beads database and that the issues table exists (SHOW TABLES)
- Run schema migration/upgrade so the beads schema matches this bd version
- Check connectivity stability and permissions on the issues table
Example fix
// before
db.QueryRowContext(ctx, "SELECT COUNT(*) FROM issues") // table missing in wrong db
// after
if err := ensureBeadsSchema(db); err != nil { return err } // creates/migrates schema first Defensive patterns
Strategy: validation
Validate before calling
var one int
if err := db.QueryRowContext(ctx, "SELECT 1 FROM issues LIMIT 1").Scan(&one); err != nil {
// schema missing — run migrations before counting
} Try / catch
if err != nil && strings.Contains(err.Error(), "failed to count issues") {
var mysqlErr *mysql.MySQLError
if errors.As(errors.Unwrap(err), &mysqlErr) && mysqlErr.Number == 1146 { /* table missing: migrate */ }
} Prevention
- Confirm the DSN points at the beads database name
- Run bd schema migrations on upgrade before doctor checks
- Check connectivity stability between ping and queries
When it happens
Trigger: QueryRowContext on the issues table errors: table missing (empty/uninitialized or wrong database), connection dropped mid-query, permission denied, or context deadline exceeded.
Common situations: Connecting to a Dolt database without the beads schema (fresh server, wrong dbname); server restarted between ping and query; schema version mismatch after upgrade.
Understand the failure class
Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.
Related errors
- failed to recompute is_blocked: %w
- server diagnostics failed: %w
- delete wisp aux rows: %w
- clone from %s succeeded, but the database needs %d schema %s
- no beads configuration found in %s
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/f772fc413aede207.
Report an issue: GitHub.