{"record":{"id":"aed10c153c2b48bb","repo":"gastownhall/beads","slug":"db-rawsql-query-columns-w","errorCode":null,"errorMessage":"db: RawSQL Query: columns: %w","messagePattern":"db: RawSQL Query: columns: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/raw_sql.go","lineNumber":29,"sourceCode":"\treturn &rawSQLRepositoryImpl{runner: runner}\n}\n\ntype rawSQLRepositoryImpl struct {\n\trunner Runner\n}\n\nvar _ domain.RawSQLRepository = (*rawSQLRepositoryImpl)(nil)\n\nfunc (r *rawSQLRepositoryImpl) Query(ctx context.Context, query string, args ...any) (*domain.RawSQLResult, error) {\n\trows, err := r.runner.QueryContext(ctx, query, args...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"db: RawSQL Query: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\tcolumns, err := rows.Columns()\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"db: RawSQL Query: columns: %w\", err)\n\t}\n\n\tresult := &domain.RawSQLResult{Columns: columns}\n\tfor rows.Next() {\n\t\tvalues := make([]any, len(columns))\n\t\tptrs := make([]any, len(columns))\n\t\tfor i := range values {\n\t\t\tptrs[i] = &values[i]\n\t\t}\n\t\tif err := rows.Scan(ptrs...); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"db: RawSQL Query: scan: %w\", err)\n\t\t}\n\t\tfor i, v := range values {\n\t\t\tif b, ok := v.([]byte); ok {\n\t\t\t\tvalues[i] = string(b)\n\t\t\t}\n\t\t}\n\t\tresult.Rows = append(result.Rows, values)","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/raw_sql.go#L11-L47","documentation":"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.","triggerScenarios":"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).","commonSituations":"Network interruption mid-query; drivers that do not support column metadata for certain statements; server restart during query; connection pool serving a broken connection.","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"],"exampleFix":"// before\nres, err := rawRepo.Query(ctx, q) // single attempt\n// after\nres, err := rawRepo.Query(ctx, q)\nif isTransientNetErr(err) {\n    time.Sleep(backoff)\n    res, err = rawRepo.Query(ctx, q)\n}","handlingStrategy":"retry","validationCode":"// health-check connection before critical queries\nif err := db.PingContext(ctx); err != nil { /* reconnect first */ }","typeGuard":null,"tryCatchPattern":"res, err := rawRepo.Query(ctx, q, args...)\nif err != nil && strings.Contains(err.Error(), \"columns: \") {\n    time.Sleep(200 * time.Millisecond)\n    res, err = rawRepo.Query(ctx, q, args...) // one retry\n}","preventionTips":["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"],"tags":["go","database","driver","metadata"],"backgroundTag":"sql-columns-metadata-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}