{"record":{"id":"50cb09e145cda923","repo":"gastownhall/beads","slug":"db-dependencysqlrepository-countallforids-from-s","errorCode":null,"errorMessage":"db: DependencySQLRepository.CountAllForIDs from %s: %w","messagePattern":"db: DependencySQLRepository\\.CountAllForIDs from (.+?): %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/dependency.go","lineNumber":818,"sourceCode":"\t\targs := make([]any, 0, 2*len(batch))\n\t\tfor i, id := range batch {\n\t\t\tplaceholders[i] = \"?\"\n\t\t\targs = append(args, id)\n\t\t}\n\t\tfor _, id := range batch {\n\t\t\targs = append(args, id)\n\t\t}\n\t\tph := strings.Join(placeholders, \",\")\n\t\tvar count int\n\t\t//nolint:gosec // G201: table is one of two hardcoded constants; ? placeholders only.\n\t\terr := r.runner.QueryRowContext(ctx,\n\t\t\tfmt.Sprintf(\"SELECT COUNT(*) FROM %s WHERE issue_id IN (%s) OR %s IN (%s)\", table, ph, issueops.DepTargetExpr, ph),\n\t\t\targs...).Scan(&count)\n\t\tif err != nil {\n\t\t\tif opts.UseWispsTable && dberrors.IsTableNotExist(err) {\n\t\t\t\treturn total, nil\n\t\t\t}\n\t\t\treturn total, fmt.Errorf(\"db: DependencySQLRepository.CountAllForIDs from %s: %w\", table, err)\n\t\t}\n\t\ttotal += count\n\t}\n\treturn total, nil\n}\n\nfunc (r *dependencySQLRepositoryImpl) ListWithIssueMetadata(ctx context.Context, sourceID string, opts domain.DepListOpts) ([]*types.IssueWithDependencyMetadata, error) {\n\tvar out []*types.IssueWithDependencyMetadata\n\tif opts.Direction == domain.DepDirectionOut || opts.Direction == domain.DepDirectionBoth {\n\t\tdeps, err := issueops.GetDependenciesWithMetadataInTx(ctx, r.runner, sourceID)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tout = append(out, filterDepsByType(deps, opts.Types)...)\n\t}\n\tif opts.Direction == domain.DepDirectionIn || opts.Direction == domain.DepDirectionBoth {\n\t\tdeps, err := issueops.GetDependentsWithMetadataInTx(ctx, r.runner, sourceID)\n\t\tif err != nil {","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/dependency.go#L800-L836","documentation":"CountAllForIDs runs SELECT COUNT(*) over dependencies (or wisp_dependencies) batches and scans the result. This error wraps any Scan/SQL failure of that count query, except the tolerated 'table not exist' case when opts.UseWispsTable is set (missing wisps table counts as zero). It means the counting query itself failed against the given table.","triggerScenarios":"Calling CountAllForIDs(ctx, ids, opts) where the COUNT query errors: unknown table (when not tolerating it), SQL syntax/engine error, connection failure, or scan failure on the count column.","commonSituations":"Corrupted or missing dependencies table after a failed migration; querying wisp_dependencies without UseWispsTable set so the missing-table tolerance is bypassed; database connection dropped mid-batch.","solutions":["Check the table named in the error exists; run database repair/migration if it is missing.","If you intend wisp counts, set opts.UseWispsTable so a missing wisp_dependencies table is tolerated as zero.","Verify database connectivity and re-run the count.","Inspect the wrapped cause (%w) with errors.Unwrap for the driver-specific error."],"exampleFix":"// before: opts missing wisps flag, missing wisp table becomes hard error\nn, err := repo.CountAllForIDs(ctx, ids, domain.DepCountsOpts{})\n// after: tolerate missing wisp table\ntotal, err := repo.CountAllForIDs(ctx, ids, domain.DepCountsOpts{UseWispsTable: true})","handlingStrategy":"fallback","validationCode":"if useWisps && !wispTableExists(ctx, db) {\n    // missing wisp table counts as zero only with UseWispsTable set\n    opts.UseWispsTable = true\n}","typeGuard":"func isMissingTableErr(err error) bool {\n    return dberrors.IsTableNotExist(err)\n}","tryCatchPattern":"n, err := repo.CountAllForIDs(ctx, ids, opts)\nif err != nil {\n    if dberrors.IsTableNotExist(errors.Unwrap(err)) {\n        n = 0 // treat missing table as no rows\n    } else {\n        return fmt.Errorf(\"dep count: %w\", err)\n    }\n}","preventionTips":["Set UseWispsTable correctly for the plane you are counting.","Run schema migrations before bulk operations.","Wrap counts with a timeout context to avoid hangs on large tables."],"tags":["database","sql","count","missing-table"],"backgroundTag":"sql-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}