gastownhall/beads · error
db: LabelSQLRepository.CountAllForIDs: %w
Error message
db: LabelSQLRepository.CountAllForIDs: %w
What it means
LabelSQLRepository.CountAllForIDs failed because the shared CountRowsForIssueIDsInTx helper returned an error while counting rows for the given IDs in the label table. Like DeleteAllForIDs, a missing wisps table is treated as zero, so this error indicates a genuine count/query failure.
Source
Thrown at internal/storage/domain/db/label.go:242
total += int(n)
}
return total, nil
}
func (r *labelSQLRepositoryImpl) CountAllForIDs(ctx context.Context, ids []string, opts domain.LabelOpts) (int, error) {
if len(ids) == 0 {
return 0, nil
}
table := "labels"
if opts.UseWispsTable {
table = "wisp_labels"
}
count, err := issueops.CountRowsForIssueIDsInTx(ctx, r.runner, table, ids)
if err != nil {
if opts.UseWispsTable && dberrors.IsTableNotExist(err) {
return 0, nil
}
return 0, fmt.Errorf("db: LabelSQLRepository.CountAllForIDs: %w", err)
}
return count, nil
}
View on GitHub (pinned to 71377f2769)
Solutions
- Unwrap the error for the driver cause (no such table, too many parameters, connection lost)
- Ensure schema migrations have created the label table
- Batch large ids slices into chunks below the driver's parameter limit
- Verify database connectivity and that the transaction/runner is still valid
Example fix
// before
count, err := repo.CountAllForIDs(ctx, hugeIDList, opts)
// after
total := 0
for i := 0; i < len(hugeIDList); i += 500 {
c, err := repo.CountAllForIDs(ctx, hugeIDList[i:min(i+500, len(hugeIDList))], opts)
if err != nil { return err }
total += c
} Defensive patterns
Strategy: validation
Validate before calling
// pre-check table existence and batch ids
if len(ids) == 0 { return 0, nil }
// e.g. SELECT COUNT(*) FROM information_schema.tables WHERE table_name='issue_labels' Try / catch
count, err := repo.CountAllForIDs(ctx, ids, opts)
if err != nil {
if dberrors.IsTableNotExist(errors.Unwrap(err)) && opts.UseWispsTable {
return 0, nil
}
return err
} Prevention
- Ensure migrations ran before counting
- Batch large ID lists
- Check transaction/runner validity in long-lived code paths
- Handle table-not-exist for wisps mode explicitly
When it happens
Trigger: Calling CountAllForIDs when the underlying SELECT COUNT fails: table missing in non-wisps mode, SQL error, too many placeholders for the ids slice, or connection failure.
Common situations: Migrations not applied so the table is absent; ids list exceeding driver parameter limits; transaction/runner in a bad state; database locked or unreachable.
Related errors
- failed to begin transaction: %w
- failed to recompute is_blocked: %w
- failed to commit is_blocked repairs: %w
- failed to query orphaned dependencies: %w
- row iteration error: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/95fe2ab8705791dd.
Report an issue: GitHub.