{"record":{"id":"435385c28c5b4a30","repo":"gastownhall/beads","slug":"check-issue-existence-in-s-rows-w","errorCode":null,"errorMessage":"check issue existence in %s: rows: %w","messagePattern":"check issue existence in (.+?): rows: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/edges.go","lineNumber":170,"sourceCode":"\t\t\trows, err := tx.QueryContext(ctx, fmt.Sprintf(\n\t\t\t\t\"SELECT id FROM %s WHERE id IN (%s)\", table, strings.Join(placeholders, \",\")), args...)\n\t\t\tif err != nil {\n\t\t\t\tif isTableNotExistError(err) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"check issue existence in %s: %w\", table, err)\n\t\t\t}\n\t\t\tfor rows.Next() {\n\t\t\t\tvar id string\n\t\t\t\tif scanErr := rows.Scan(&id); scanErr != nil {\n\t\t\t\t\t_ = rows.Close()\n\t\t\t\t\treturn nil, fmt.Errorf(\"check issue existence in %s: scan: %w\", table, scanErr)\n\t\t\t\t}\n\t\t\t\tpresent[id] = struct{}{}\n\t\t\t}\n\t\t\t_ = rows.Close()\n\t\t\tif err := rows.Err(); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"check issue existence in %s: rows: %w\", table, err)\n\t\t\t}\n\t\t}\n\t}\n\treturn present, nil\n}\n","sourceCodeStart":152,"sourceCodeEnd":176,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/edges.go#L152-L176","documentation":"PresentIssueOrWispIDsInTx collects the IDs that actually exist in the issues/wisps tables by scanning result rows. After iterating rows it calls rows.Err() and wraps any driver-level iteration failure (network drop, context cancellation, driver decode error mid-stream) with this message. It means the existence check did not complete, so the returned set may be incomplete and must not be trusted.","triggerScenarios":"Calling ExecuteEdgeCount or ExecuteEdgeRead when the underlying `SELECT id FROM ... WHERE id IN (...)` row stream fails after the query itself succeeded — e.g. the Dolt/MySQL connection breaks or the context is cancelled while rows are being iterated.","commonSituations":"Long-running edge operations interrupted by an idle-connection timeout on the database; a request context cancelled by an HTTP client disconnect; flaky network between bd and a remote Dolt server.","solutions":["Retry the edge operation; the error is transient if caused by connection/context interruption.","Check the wrapped cause (%w) for context.Canceled / context.DeadlineExceeded and increase the timeout or fix the caller that cancelled.","Verify the database connection is healthy (bd doctor / ping) if it recurs.","Check Dolt server logs for connection resets if using a remote database."],"exampleFix":"// before\npresent, err := PresentIssueOrWispIDsInTx(ctx, tx, ids)\nif err != nil { return err }\n// after\npresent, err := PresentIssueOrWispIDsInTx(ctx, tx, ids)\nif err != nil {\n    if errors.Is(err, context.DeadlineExceeded) {\n        ctx = context.Background() // or raise the deadline\n        present, err = PresentIssueOrWispIDsInTx(ctx, tx, ids)\n    }\n    if err != nil { return err }\n}","handlingStrategy":"retry","validationCode":"if err := db.PingContext(ctx); err != nil { return fmt.Errorf(\"db unavailable: %w\", err) }\nif ctx.Err() != nil { return ctx.Err() }","typeGuard":"func isRowsIterationErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"check issue existence\") && strings.Contains(err.Error(), \": rows: \")\n}","tryCatchPattern":"present, err := PresentIssueOrWispIDsInTx(ctx, tx, ids)\nif err != nil {\n    if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {\n        return retryWithFreshCtx(ctx)\n    }\n    return fmt.Errorf(\"edge existence check failed: %w\", err)\n}","preventionTips":["Set generous but bounded context deadlines for edge operations.","Keep the database connection alive (idle timeouts above longest query).","Avoid cancelling parent contexts mid-transaction.","Monitor connection-reset logs on the Dolt server."],"tags":["go","sql","storage","row-iteration"],"backgroundTag":"sql-rows-iteration-error","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}