{"record":{"id":"a3722056824a4ec9","repo":"gastownhall/beads","slug":"row-iteration-error-w","errorCode":null,"errorMessage":"row iteration error: %w","messagePattern":"row iteration error: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/doctor/fix/validation.go","lineNumber":71,"sourceCode":"\t\treturn fmt.Errorf(\"failed to query orphaned dependencies: %w\", err)\n\t}\n\tdefer rows.Close()\n\n\ttype orphan struct {\n\t\tdepTable    string\n\t\tissueID     string\n\t\tdependsOnID string\n\t}\n\tvar orphans []orphan\n\n\tfor rows.Next() {\n\t\tvar o orphan\n\t\tif err := rows.Scan(&o.depTable, &o.issueID, &o.dependsOnID); err == nil {\n\t\t\torphans = append(orphans, o)\n\t\t}\n\t}\n\tif err := rows.Err(); err != nil {\n\t\treturn fmt.Errorf(\"row iteration error: %w\", err)\n\t}\n\n\tif len(orphans) == 0 {\n\t\tfmt.Println(\"  No orphaned dependencies to fix\")\n\t\treturn nil\n\t}\n\n\t// Delete orphaned dependencies\n\t// Uses explicit transaction so writes persist when @@autocommit is OFF\n\t// (e.g. Dolt server started with --no-auto-commit).\n\tshowIndividual := verbose || len(orphans) < 20\n\ttx, err := db.Begin()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to begin transaction: %w\", err)\n\t}\n\tvar removed int\n\tfor _, o := range orphans {\n\t\tvar err error","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/doctor/fix/validation.go#L53-L89","documentation":"After streaming result rows, OrphanedDependencies checks rows.Err() — the mandatory database/sql step that surfaces errors encountered during iteration (network drop mid-result-set, driver decode failure). If iteration failed, the collected orphan list may be incomplete, so the function refuses to continue and wraps the error as \"row iteration error\" to avoid deleting only a partial set.","triggerScenarios":"rows.Next()/rows.Scan sequence hits a driver-level error while fetching the result set: connection terminated mid-query on a remote Dolt server, packet corruption/timeout, or a driver decode error on a column value.","commonSituations":"Large result set over a flaky connection to a networked Dolt server; server killed or OOM during the SELECT; keep-alive/proxy timeout cutting the connection while rows stream; Dolt version mismatch producing unexpected column values.","solutions":["Re-run the fix — this is usually transient; the SELECT restarts from scratch.","Check Dolt server logs for a crash or connection kill around the time of the run; stabilize the server/connection.","Increase connection/network timeouts if large result sets are being truncated by a proxy or idle timeout.","Upgrade the Dolt driver/server if decode errors recur (version mismatch between client driver and server)."],"exampleFix":"// before: connection drops mid-iteration, partial orphans discarded safely\nfor rows.Next() {\n\tif err := rows.Scan(&o.depTable, &o.issueID, &o.dependsOnID); err == nil {\n\t\torphans = append(orphans, o)\n\t}\n}\nif err := rows.Err(); err != nil {\n\treturn fmt.Errorf(\"row iteration error: %w\", err)\n}\n// after: retry the whole function on a healthy connection\n// (fix has no partial side effects at this stage — the DELETE transaction has not started)","handlingStrategy":"retry","validationCode":"// probe connectivity before a long-running fix\nif err := db.PingContext(ctx); err != nil {\n\treturn fmt.Errorf(\"database unreachable, aborting fix: %w\", err)\n}","typeGuard":"var netErr net.Error\nif errors.As(err, &netErr) && netErr.Timeout() {\n\t// transient network failure during row iteration — safe to retry\n}","tryCatchPattern":"err := fix.OrphanedDependencies(path, verbose)\nif err != nil && strings.Contains(err.Error(), \"row iteration error\") {\n\t// no writes have happened yet; safe to retry once\n\terr = fix.OrphanedDependencies(path, verbose)\n}\nif err != nil {\n\tlog.Fatalf(\"orphan fix failed: %v\", err)\n}","preventionTips":["Run fixes against a local or stable network connection to the Dolt server.","Avoid running doctor --fix during server restarts, backups, or heavy load windows.","Increase driver/proxy timeouts if result sets are large.","Remember the failure occurs before any deletes, so retrying the whole fix is safe."],"tags":["go","database","dolt","sql","row-iteration"],"backgroundTag":"database-connection-dropped","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}