{"record":{"id":"b17a359797b2e8cb","repo":"gastownhall/beads","slug":"search-s-hydrate-rows-w","errorCode":null,"errorMessage":"search %s (hydrate): rows: %w","messagePattern":"search (.+?) \\(hydrate\\): rows: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/search.go","lineNumber":474,"sourceCode":"\t\tproj.columns(tables), fetchFrom, strings.Join(placeholders, \",\"))\n\n\tfetchRows, err := tx.QueryContext(ctx, fetchSQL, fetchArgs...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"search %s (hydrate): %w\", tables.Main, err)\n\t}\n\n\titemMap := make(map[string]T, len(ids))\n\tfor fetchRows.Next() {\n\t\titem, scanErr := proj.scan(fetchRows)\n\t\tif scanErr != nil {\n\t\t\t_ = fetchRows.Close()\n\t\t\treturn nil, fmt.Errorf(\"search %s (hydrate): scan: %w\", tables.Main, scanErr)\n\t\t}\n\t\titemMap[proj.id(item)] = item\n\t}\n\t_ = fetchRows.Close()\n\tif err := fetchRows.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"search %s (hydrate): rows: %w\", tables.Main, err)\n\t}\n\n\t// Reorder to preserve the id-scan ORDER BY.\n\tresults := make([]T, 0, len(ids))\n\tfor _, id := range ids {\n\t\tif item, ok := itemMap[id]; ok {\n\t\t\tresults = append(results, item)\n\t\t}\n\t}\n\n\tif proj.hydrate != nil && len(results) > 0 {\n\t\tif err := proj.hydrate(ctx, tx, tables, results, filter); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"search %s (pattern B): %w\", tables.Main, err)\n\t\t}\n\t}\n\n\treturn results, nil\n}","sourceCodeStart":456,"sourceCodeEnd":492,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/search.go#L456-L492","documentation":"searchTablePatternBT wraps the error returned by fetchRows.Err() after the Pattern B batch fetch finished iterating: the driver reported a failure while streaming rows (not a scan error, not an initial query error). This catches mid-result-set failures like dropped connections or backend errors surfaced during row retrieval.","triggerScenarios":"During iteration of the WHERE id IN (...) fetch, the underlying connection breaks, the server aborts the query, or ctx is cancelled between Next() calls — the driver sets an error on the Rows that only rows.Err() surfaces after Close.","commonSituations":"Network drop to a remote Dolt server mid-fetch; query killed by a server-side timeout; ctx deadline exceeded on a slow disk; process memory pressure causing driver-level failures.","solutions":["Read the wrapped rows error; retry the search if it was transient (connection reset, timeout)","Raise the context timeout or remove the deadline for large fetches","Reduce filter.Limit to shrink the batch fetch","Check server logs (Dolt/SQLite) for query aborts or kills around the timestamp","Verify network stability to the database host if using a remote Dolt server"],"exampleFix":"// before: short default timeout killed a large batch fetch mid-stream\nctx := context.Background()\n// after: bound generously for large result sets\nctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)\ndefer cancel()\nrows, err := searchIssues(ctx, tx, q, filter)","handlingStrategy":"retry","validationCode":"// pre-check connection health before large batch fetches\nif err := tx.PingContext(ctx); err != nil {\n    return fmt.Errorf(\"connection unhealthy before search: %w\", err)\n}\nif ctx.Err() != nil { return ctx.Err() }","typeGuard":"func isRowsIterationErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \": rows: \")\n}","tryCatchPattern":"var res []Issue\nvar err error\nfor attempt := 0; attempt < 3; attempt++ {\n    res, err = searchIssues(ctx, tx, q, filter)\n    if err == nil || !isRowsIterationErr(err) { break }\n    time.Sleep(backoff(attempt)) // retry transient mid-stream failures\n}\nif err != nil { return err }","preventionTips":["Use generous context timeouts for large fetches","Enable connection retry/backoff at the driver layer","Monitor network stability to remote Dolt servers","Reduce batch sizes (lower filter.Limit) on flaky links"],"tags":["database","sql","rows-iteration","connection"],"backgroundTag":"sql-rows-iteration-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}