{"record":{"id":"439168fe0c2692a2","repo":"gastownhall/beads","slug":"count-by-id-w","errorCode":null,"errorMessage":"count by id: %w","messagePattern":"count by id: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/dependency.go","lineNumber":557,"sourceCode":"\t\tUseWispsTable: useWisp,\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"iter dep metadata: %w\", err)\n\t}\n\treturn it, nil\n}\n\nfunc (u *dependencyUseCaseImpl) countByID(ctx context.Context, sourceID string, filter DepListFilter, useWisp bool) (int64, error) {\n\tif sourceID == \"\" {\n\t\treturn 0, fmt.Errorf(\"count by id: sourceID must not be empty\")\n\t}\n\tn, err := u.depRepo.CountByID(ctx, sourceID, DepListOpts{\n\t\tTypes:         filter.Types,\n\t\tDirection:     filter.Direction,\n\t\tUseWispsTable: useWisp,\n\t})\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"count by id: %w\", err)\n\t}\n\treturn n, nil\n}\n\nfunc (u *dependencyUseCaseImpl) list(ctx context.Context, ids []string, filter DepListFilter, useWisp bool) (DepBulkResult, error) {\n\tif len(ids) == 0 {\n\t\treturn DepBulkResult{\n\t\t\tOutgoing: map[string][]*types.Dependency{},\n\t\t\tIncoming: map[string][]*types.Dependency{},\n\t\t}, nil\n\t}\n\tout, err := u.depRepo.ListByIssueIDs(ctx, ids, DepListOpts{\n\t\tTypes:         filter.Types,\n\t\tDirection:     filter.Direction,\n\t\tUseWispsTable: useWisp,\n\t})\n\tif err != nil {\n\t\treturn DepBulkResult{}, fmt.Errorf(\"list deps: %w\", err)","sourceCodeStart":539,"sourceCodeEnd":575,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/dependency.go#L539-L575","documentation":"Wraps a repository failure from depRepo.CountByID after the empty-ID guard. The dependency count query failed at the storage layer; the root cause is preserved via %w.","triggerScenarios":"Calling CountByIssueID or CountByWispID with a valid sourceID where CountByID on depRepo returns an error (with the filter's Types/Direction/UseWispsTable applied).","commonSituations":"DB outage or lock contention; count query timeout on nodes with very large dependency fan-out; wisps variant when the wisps table is absent or inconsistent.","solutions":["Read the wrapped cause; handle transient DB errors with retry/backoff","Verify migrations and table presence for the wisp variant","Simplify the filter (e.g. drop Types/Direction constraints) to isolate the failing query","Check context deadline adequacy"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if sourceID == \"\" {\n\treturn fmt.Errorf(\"sourceID required\")\n}","typeGuard":null,"tryCatchPattern":"n, err := u.CountByIssueID(ctx, sourceID, filter)\nif err != nil {\n\tif isTransient(errors.Unwrap(err)) {\n\t\t// exponential backoff retry; counts are read-only\n\t}\n\treturn 0, err\n}","preventionTips":["Apply backoff retry for transient DB errors","Verify wisps table for CountByWispID deployments","Reduce filter complexity if count queries time out","Keep migrations aligned with the beads version"],"tags":["storage","dependency","count","wrapped-error"],"backgroundTag":"dependency-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}