gastownhall/beads · error
failed to scan comment: %w
Error message
failed to scan comment: %w
What it means
scanComments fails when a comment row cannot be scanned into types.Comment — the result set's columns don't match the scan destinations (ID, IssueID, Author, Text, CreatedAt). Typically caused by NULLs in non-nullable fields or a column type/count mismatch after schema changes. The raw sql error is wrapped for inspection.
Source
Thrown at internal/storage/dolt/events.go:185
// GetCommentCounts returns the number of comments for each issue in a single batch query.
// Delegates to issueops.GetCommentCountsInTx for shared query logic.
func (s *DoltStore) GetCommentCounts(ctx context.Context, issueIDs []string) (map[string]int, error) {
var result map[string]int
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
var err error
result, err = issueops.GetCommentCountsInTx(ctx, tx, issueIDs)
return err
})
return result, err
}
// scanComments scans comment rows into a slice.
func scanComments(rows *sql.Rows) ([]*types.Comment, error) {
var comments []*types.Comment
for rows.Next() {
var c types.Comment
if err := rows.Scan(&c.ID, &c.IssueID, &c.Author, &c.Text, &c.CreatedAt); err != nil {
return nil, fmt.Errorf("failed to scan comment: %w", err)
}
comments = append(comments, &c)
}
return comments, rows.Err()
}
View on GitHub (pinned to 71377f2769)
Solutions
- Find the offending row(s) via SQL (`SELECT * FROM comments WHERE author IS NULL OR text IS NULL OR created_at IS NULL`) and fix or delete them.
- If you altered the comments table, restore the expected schema (column names, order, types, NOT NULL constraints).
- Run any pending migrations (`bd doctor` / migrate) so the schema matches the code's expectations.
- As a last resort, export good data, recreate the table with the canonical schema, and re-import.
Example fix
// before: manual insert leaving NULLs
INSERT INTO comments (id, issue_id, text) VALUES ('c1', 'bd-1', 'hi');
// after: supply all non-nullable columns
INSERT INTO comments (id, issue_id, author, text, created_at)
VALUES ('c1', 'bd-1', 'alice', 'hi', NOW()); Defensive patterns
Strategy: validation
Validate before calling
// SQL: detect rows that will fail the scan before reading via bd SELECT id FROM comments WHERE author IS NULL OR text IS NULL OR created_at IS NULL OR issue_id IS NULL;
Type guard
func IsCommentScanError(err error) bool {
return err != nil && strings.Contains(err.Error(), "failed to scan comment")
} Try / catch
comments, err := store.GetIssueComments(ctx, issueID)
if err != nil && strings.Contains(err.Error(), "failed to scan comment") {
return fmt.Errorf("corrupt comment row; fix NULLs in comments table: %w", err)
} Prevention
- Never insert comment rows manually without all required columns.
- Enforce NOT NULL constraints in the comments schema and rely on them.
- Validate schema after restores/backups before normal use.
- Use nullable Go scan types if a column is legitimately optional.
When it happens
Trigger: A comment row has NULL author, text, or created_at (e.g. inserted manually via dolt sql); the comments table was altered so column order/types differ; a schema migration left mixed-format rows.
Common situations: Hand-editing the database with `dolt sql` and omitting required fields; upgrading bd across versions where the Comment struct gained fields the old schema can't satisfy; restoring a partial backup missing some columns.
Related errors
- ErrScan
- failed to recompute is_blocked: %w
- failed to scan dependency keys: %w
- failed to scan federation peer: %w
- failed to get comments: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/be2a1d506da7fd8a.
Report an issue: GitHub.