{"record":{"id":"95fe2ab8705791dd","repo":"gastownhall/beads","slug":"db-labelsqlrepository-countallforids-w","errorCode":null,"errorMessage":"db: LabelSQLRepository.CountAllForIDs: %w","messagePattern":"db: LabelSQLRepository\\.CountAllForIDs: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/db/label.go","lineNumber":242,"sourceCode":"\t\ttotal += int(n)\n\t}\n\treturn total, nil\n}\n\nfunc (r *labelSQLRepositoryImpl) CountAllForIDs(ctx context.Context, ids []string, opts domain.LabelOpts) (int, error) {\n\tif len(ids) == 0 {\n\t\treturn 0, nil\n\t}\n\ttable := \"labels\"\n\tif opts.UseWispsTable {\n\t\ttable = \"wisp_labels\"\n\t}\n\tcount, err := issueops.CountRowsForIssueIDsInTx(ctx, r.runner, table, ids)\n\tif err != nil {\n\t\tif opts.UseWispsTable && dberrors.IsTableNotExist(err) {\n\t\t\treturn 0, nil\n\t\t}\n\t\treturn 0, fmt.Errorf(\"db: LabelSQLRepository.CountAllForIDs: %w\", err)\n\t}\n\treturn count, nil\n}\n","sourceCodeStart":224,"sourceCodeEnd":246,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/db/label.go#L224-L246","documentation":"LabelSQLRepository.CountAllForIDs failed because the shared CountRowsForIssueIDsInTx helper returned an error while counting rows for the given IDs in the label table. Like DeleteAllForIDs, a missing wisps table is treated as zero, so this error indicates a genuine count/query failure.","triggerScenarios":"Calling CountAllForIDs when the underlying SELECT COUNT fails: table missing in non-wisps mode, SQL error, too many placeholders for the ids slice, or connection failure.","commonSituations":"Migrations not applied so the table is absent; ids list exceeding driver parameter limits; transaction/runner in a bad state; database locked or unreachable.","solutions":["Unwrap the error for the driver cause (no such table, too many parameters, connection lost)","Ensure schema migrations have created the label table","Batch large ids slices into chunks below the driver's parameter limit","Verify database connectivity and that the transaction/runner is still valid"],"exampleFix":"// before\ncount, err := repo.CountAllForIDs(ctx, hugeIDList, opts)\n// after\ntotal := 0\nfor i := 0; i < len(hugeIDList); i += 500 {\n    c, err := repo.CountAllForIDs(ctx, hugeIDList[i:min(i+500, len(hugeIDList))], opts)\n    if err != nil { return err }\n    total += c\n}","handlingStrategy":"validation","validationCode":"// pre-check table existence and batch ids\nif len(ids) == 0 { return 0, nil }\n// e.g. SELECT COUNT(*) FROM information_schema.tables WHERE table_name='issue_labels'","typeGuard":null,"tryCatchPattern":"count, err := repo.CountAllForIDs(ctx, ids, opts)\nif err != nil {\n    if dberrors.IsTableNotExist(errors.Unwrap(err)) && opts.UseWispsTable {\n        return 0, nil\n    }\n    return err\n}","preventionTips":["Ensure migrations ran before counting","Batch large ID lists","Check transaction/runner validity in long-lived code paths","Handle table-not-exist for wisps mode explicitly"],"tags":["go","database","sql","count"],"backgroundTag":"sql-query-execution-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}