gastownhall/beads · error
failed to get comments: %w
Error message
failed to get comments: %w
What it means
GetIssueComments fails when the SELECT of comments for an issue cannot be executed. The error from the query layer (bad table, connection loss, canceled context) is wrapped as 'failed to get comments'. Reached via IterIssueComments when iterating issue comments.
Source
Thrown at internal/storage/dolt/events.go:135
return result, nil
}
// GetIssueComments retrieves all comments for an issue
func (s *DoltStore) GetIssueComments(ctx context.Context, issueID string) ([]*types.Comment, error) {
table := "comments"
if s.isActiveWisp(ctx, issueID) {
table = "wisp_comments"
}
//nolint:gosec // G201: table is hardcoded
rows, err := s.queryContext(ctx, fmt.Sprintf(`
SELECT id, issue_id, author, text, created_at
FROM %s
WHERE issue_id = ?
ORDER BY created_at ASC, id ASC
`, table), issueID)
if err != nil {
return nil, fmt.Errorf("failed to get comments: %w", err)
}
defer rows.Close()
return scanComments(rows)
}
// GetIssueCommentsPage returns one keyset page of an issue's comments in
// (created_at ASC, id ASC) order, resuming strictly after the cursor. See the
// storage.Storage doc for the ordering, sargability, and page-walk-equals-full-
// read contract.
func (s *DoltStore) GetIssueCommentsPage(ctx context.Context, issueID string, after storage.CommentPageCursor, limit int) ([]*types.Comment, error) {
var result []*types.Comment
err := s.withReadTx(ctx, func(tx *sql.Tx) error {
var err error
result, err = issueops.GetIssueCommentsPageInTx(ctx, tx, issueID, after, limit)
return err
})
return result, errView on GitHub (pinned to 71377f2769)
Solutions
- Confirm the comments table exists with the expected columns (`dolt sql -q "DESCRIBE comments"` or equivalent).
- Run `bd doctor` to detect schema/version drift and apply migrations.
- Restart the bd process / Dolt server if the error indicates a broken connection.
- Check that the issue ID passed to GetIssueComments is a valid, correctly formatted ID.
Example fix
// before: swallowing the distinction between empty and failed
comments, err := store.GetIssueComments(ctx, id)
if err != nil {
comments = nil
}
// after: surface the error to the user
comments, err := store.GetIssueComments(ctx, id)
if err != nil {
return fmt.Errorf("cannot list comments for %s: %w", id, err)
} Defensive patterns
Strategy: type-guard
Validate before calling
// Go: confirm the comments table exists before listing
_, err := db.Query("SELECT 1 FROM comments LIMIT 1")
if err != nil {
return fmt.Errorf("comments table missing (run migrations): %w", err)
} Type guard
func IsCommentsFetchError(err error) bool {
return err != nil && strings.Contains(err.Error(), "failed to get comments")
} Try / catch
comments, err := store.GetIssueComments(ctx, issueID)
if err != nil {
return fmt.Errorf("cannot read comments for %s: %w", issueID, err)
} Prevention
- Run migrations/doctor after any bd upgrade before reading comments.
- Use well-formed issue IDs; validate input before querying.
- Keep Dolt server sessions alive; avoid long-lived processes across server restarts.
- Check connectivity if listing comments suddenly fails repo-wide.
When it happens
Trigger: Querying comments when the comments table is missing (uninitialized/partially migrated DB), the issue_id filter references a malformed ID, the Dolt connection dropped mid-query, or the context was canceled during IterIssueComments.
Common situations: `bd show <issue>` or comment listing after a schema migration changed the comments table; reading from a database created by a newer bd version; Dolt server restart between opening the store and issuing the query.
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
- ErrQuery
- failed to scan comment: %w
- failed to check remote %s: %w
- comment counts: %w
- descendants: query: %w
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/d169c729f3b8159c.
Report an issue: GitHub.