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

  1. Unwrap the error for the driver cause (no such table, too many parameters, connection lost)
  2. Ensure schema migrations have created the label table
  3. Batch large ids slices into chunks below the driver's parameter limit
  4. 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

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


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/95fe2ab8705791dd. Report an issue: GitHub.