gastownhall/beads · error
db: RawSQL Query: columns: %w
Error message
db: RawSQL Query: columns: %w
What it means
RawSQLRepository.Query executed successfully but rows.Columns() failed while retrieving the result set's column metadata. This happens after a successful query when the connection or driver fails to describe the result columns.
Source
Thrown at internal/storage/domain/db/raw_sql.go:29
return &rawSQLRepositoryImpl{runner: runner}
}
type rawSQLRepositoryImpl struct {
runner Runner
}
var _ domain.RawSQLRepository = (*rawSQLRepositoryImpl)(nil)
func (r *rawSQLRepositoryImpl) Query(ctx context.Context, query string, args ...any) (*domain.RawSQLResult, error) {
rows, err := r.runner.QueryContext(ctx, query, args...)
if err != nil {
return nil, fmt.Errorf("db: RawSQL Query: %w", err)
}
defer rows.Close()
columns, err := rows.Columns()
if err != nil {
return nil, fmt.Errorf("db: RawSQL Query: columns: %w", err)
}
result := &domain.RawSQLResult{Columns: columns}
for rows.Next() {
values := make([]any, len(columns))
ptrs := make([]any, len(columns))
for i := range values {
ptrs[i] = &values[i]
}
if err := rows.Scan(ptrs...); err != nil {
return nil, fmt.Errorf("db: RawSQL Query: scan: %w", err)
}
for i, v := range values {
if b, ok := v.([]byte); ok {
values[i] = string(b)
}
}
result.Rows = append(result.Rows, values)View on GitHub (pinned to 71377f2769)
Solutions
- Unwrap the error to see the driver-level cause and check connection stability
- Retry the query — this is often a transient connection issue
- Verify the driver/transport supports column metadata for your query type
- Check server logs for aborted connections around the time of the failure
Example fix
// before
res, err := rawRepo.Query(ctx, q) // single attempt
// after
res, err := rawRepo.Query(ctx, q)
if isTransientNetErr(err) {
time.Sleep(backoff)
res, err = rawRepo.Query(ctx, q)
} Defensive patterns
Strategy: retry
Validate before calling
// health-check connection before critical queries
if err := db.PingContext(ctx); err != nil { /* reconnect first */ } Try / catch
res, err := rawRepo.Query(ctx, q, args...)
if err != nil && strings.Contains(err.Error(), "columns: ") {
time.Sleep(200 * time.Millisecond)
res, err = rawRepo.Query(ctx, q, args...) // one retry
} Prevention
- Set reasonable pool lifetimes to recycle stale connections
- Ping or validate connections before long operations
- Upgrade drivers with metadata/prepare bugs
- Retry transient metadata failures with backoff
When it happens
Trigger: Calling Query when the connection drops between query execution and metadata fetch, or the driver cannot describe columns for the result (driver limitation, prepared-statement issues).
Common situations: Network interruption mid-query; drivers that do not support column metadata for certain statements; server restart during query; connection pool serving a broken connection.
Related errors
- failed to open migration connection: %w
- db: GetMetadata %s: %w
- db: SetMetadata %s: %w
- db: LabelSQLRepository.DeleteAllForIDs rows affected: %w
- ExternalDoltConfig: must set Socket or (Host, Port)
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/aed10c153c2b48bb.
Report an issue: GitHub.