{"record":{"id":"82a54626dc0a68d5","repo":"gastownhall/beads","slug":"search-count-s-rows-w","errorCode":null,"errorMessage":"search count %s: rows: %w","messagePattern":"search count (.+?): rows: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/issue_search_counts.go","lineNumber":204,"sourceCode":"\n\tvar out []*types.IssueWithCounts\n\tseen := make(map[string]bool)\n\tfor rows.Next() {\n\t\tiwc, scanErr := scanReadyWorkRowWithCounts(rows, hyd)\n\t\tif scanErr != nil {\n\t\t\treturn nil, scanErr\n\t\t}\n\t\tif iwc == nil || iwc.Issue == nil {\n\t\t\tcontinue\n\t\t}\n\t\tif seen[iwc.Issue.ID] {\n\t\t\tcontinue\n\t\t}\n\t\tseen[iwc.Issue.ID] = true\n\t\tout = append(out, iwc)\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"search count %s: rows: %w\", tables.Main, err)\n\t}\n\treturn out, nil\n}\n\nfunc (r *issueSQLRepositoryImpl) optionalTableExists(ctx context.Context, table string) (bool, error) {\n\tvar probe int\n\t//nolint:gosec // G201: table is a hardcoded constant from caller (issues, wisps, dependencies, wisp_dependencies, ...).\n\terr := r.runner.QueryRowContext(ctx, fmt.Sprintf(\"SELECT 1 FROM %s LIMIT 1\", table)).Scan(&probe)\n\tswitch {\n\tcase err == nil:\n\t\treturn true, nil\n\tcase errors.Is(err, sql.ErrNoRows):\n\t\treturn true, nil\n\tcase dberrors.IsTableNotExist(err):\n\t\treturn false, nil\n\tdefault:\n\t\treturn false, err\n\t}","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/issue_search_counts.go#L186-L222","documentation":"Wraps rows.Err() after iterating a counts mega-query result set. This error surfaces problems detected during iteration — the connection dropped or the statement failed partway through streaming rows — rather than at query start. The %s names the main table of the failing counts query.","triggerScenarios":"rows.Next() loop completes but rows.Err() is non-nil: mid-iteration network failure, server-side abort, or driver decode issue detected late.","commonSituations":"Long-running aggregate queries over big datasets losing their connection; remote Dolt server restarts mid-query; flaky network to a shared server.","solutions":["Retry the query — mid-iteration drops are usually transient","Reduce result size (filters, Lite hydration, pagination) to shorten iteration window","Check DB server stability/logs for aborts","Verify driver version compatibility"],"exampleFix":"// before\nitems, err := store.Search(ctx, bigFilter)\n// after\nitems, err := store.Search(ctx, bigFilter)\nif err != nil { items, err = store.Search(ctx, bigFilter) } // bounded retry for transient rows errors","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"items, err := store.Search(ctx, q, filter)\nif err != nil && strings.Contains(err.Error(), \"rows:\") && isTransient(err) {\n    time.Sleep(backoff)\n    items, err = store.Search(ctx, q, filter)\n}","preventionTips":["Keep result sets modest via filters and pagination","Ensure DB server keep-alive settings exceed query duration","Alert on repeated rows.Err failures — they signal network/server instability","Upgrade drivers known to have mid-scan connection bugs"],"tags":["sql","rows-iteration","network"],"backgroundTag":"sql-rows-iteration-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}