{"record":{"id":"7bf7ed0e8654e663","repo":"gastownhall/beads","slug":"count-edges-in-s-scan-w","errorCode":null,"errorMessage":"count edges in %s: scan: %w","messagePattern":"count edges in (.+?): scan: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/edge_counts.go","lineNumber":158,"sourceCode":"\t\t\tend := start + queryBatchSize\n\t\t\tif end > len(anchors) {\n\t\t\t\tend = len(anchors)\n\t\t\t}\n\t\t\tbatch := anchors[start:end]\n\t\t\tquery := buildEdgeCountQuery(plane.dependencies, plane.sources, len(batch), request)\n\t\t\trows, err := tx.QueryContext(ctx, query, edgeCountArgs(batch, request)...)\n\t\t\tif err != nil {\n\t\t\t\tif optionalBlockedTable(plane.dependencies) && isTableNotExistError(err) {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t\treturn nil, fmt.Errorf(\"count edges in %s: %w\", plane.dependencies, err)\n\t\t\t}\n\t\t\tfor rows.Next() {\n\t\t\t\tvar id string\n\t\t\t\tvar n int64\n\t\t\t\tif scanErr := rows.Scan(&id, &n); scanErr != nil {\n\t\t\t\t\t_ = rows.Close()\n\t\t\t\t\treturn nil, fmt.Errorf(\"count edges in %s: scan: %w\", plane.dependencies, scanErr)\n\t\t\t\t}\n\t\t\t\ttallies[id] += n\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(\"count edges in %s: rows: %w\", plane.dependencies, err)\n\t\t\t}\n\t\t}\n\t}\n\treturn tallies, nil\n}\n\n// buildEdgeCountQuery returns the grouped count for one dependency plane, keyed\n// by the anchor end the request's direction names.\n//\n// THE TARGET END IS ALWAYS THE COALESCE EXPRESSION, never the STORED generated\n// `depends_on_id` column. Both dependency tables define that column as\n// GENERATED ALWAYS AS the same COALESCE, and inside an aggregate the pure-Go","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/edge_counts.go#L140-L176","documentation":"tallyEdgesInTx failed while scanning a row of the grouped edge-count result into (id string, count int64). rows.Scan returned an error because the returned columns did not match the expected string/int64 shapes. The rows are closed before returning so the connection is not leaked.","triggerScenarios":"A driver returning columns whose Go types cannot convert to string/int64 (e.g. NULL id, a count column typed as unsigned bigint beyond int64, or a decimal count from a custom COUNT expression); a driver mismatch producing different column types than Dolt normally does.","commonSituations":"Using a non-Dolt/MySQL driver or a driver version whose type mapping changed; a schema where the id column is nullable and a NULL row appears; a modified buildEdgeCountQuery selecting an extra/different column while the scan still expects two.","solutions":["Check the driver's type mapping for COUNT/aggregate results (e.g. uint64 vs int64) and pin a supported driver version.","Make the query's COALESCE/COUNT output non-NULL and compatible (CAST if needed).","Inspect the wrapped scan error message — it names the offending column and Go type.","If the code was customized, re-align rows.Scan with buildEdgeCountQuery's SELECT list."],"exampleFix":"// before\nvar n int64\nif scanErr := rows.Scan(&id, &n); scanErr != nil { ... }\n// after\nvar n any // or uint64, matching the driver\ncount, ok := n.(uint64)\nif ok { n = int64(count) }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"res, err := ExecuteEdgeCount(ctx, tx, req)\nif err != nil && strings.Contains(err.Error(), \": scan: \") {\n\tlog.Errorf(\"edge count scan failure: %v\", err) // inspect driver type mapping\n}","preventionTips":["Pin a supported Dolt/MySQL driver version","Keep id columns NOT NULL","Do not customize buildEdgeCountQuery's SELECT list without updating the scan","Test counts against your actual driver, not just the default"],"tags":["database","sql","scan","type-mismatch"],"backgroundTag":"sql-scan-type-mismatch","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}