{"record":{"id":"2fd9c673ca3b081d","repo":"gastownhall/beads","slug":"countopenchildren-s-w","errorCode":null,"errorMessage":"CountOpenChildren %s: %w","messagePattern":"CountOpenChildren (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/storage/domain/issue.go","lineNumber":1757,"sourceCode":"func (u *issueUseCaseImpl) CountOpenChildren(ctx context.Context, id string) (int, error) {\n\treturn u.countOpenChildren(ctx, id, false)\n}\n\nfunc (u *issueUseCaseImpl) CountOpenWispChildren(ctx context.Context, id string) (int, error) {\n\treturn u.countOpenChildren(ctx, id, true)\n}\n\nfunc (u *issueUseCaseImpl) countOpenChildren(ctx context.Context, id string, useWisp bool) (int, error) {\n\tif id == \"\" {\n\t\treturn 0, fmt.Errorf(\"CountOpenChildren: id must not be empty\")\n\t}\n\tchildren, err := u.depRepo.ListWithIssueMetadata(ctx, id, DepListOpts{\n\t\tTypes:         []types.DependencyType{types.DepParentChild},\n\t\tDirection:     DepDirectionIn,\n\t\tUseWispsTable: useWisp,\n\t})\n\tif err != nil {\n\t\treturn 0, fmt.Errorf(\"CountOpenChildren %s: %w\", id, err)\n\t}\n\topen := 0\n\tfor _, child := range children {\n\t\tif child.Status != types.StatusClosed {\n\t\t\topen++\n\t\t}\n\t}\n\treturn open, nil\n}\n\nfunc (u *issueUseCaseImpl) GetNewlyUnblockedByClose(ctx context.Context, closedID string) ([]*types.Issue, error) {\n\treturn u.getNewlyUnblockedByClose(ctx, closedID)\n}\n\nfunc (u *issueUseCaseImpl) GetNewlyUnblockedByCloseWisp(ctx context.Context, closedID string) ([]*types.Issue, error) {\n\treturn u.getNewlyUnblockedByClose(ctx, closedID)\n}\n","sourceCodeStart":1739,"sourceCodeEnd":1775,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/domain/issue.go#L1739-L1775","documentation":"This error is returned by CountOpenChildren in the issue use-case layer when the underlying repository call ListWithIssueMetadata fails while counting non-closed children of an issue. The issue ID and the wrapped repository error are embedded so the caller can see exactly which parent issue's child count could not be computed. It is a pass-through wrapper: the root cause (storage/query failure) is preserved via %w.","triggerScenarios":"Calling CountOpenChildren (directly or via CountOpenChildrenWisp) when u.depRepo.ListWithIssueMetadata(ctx, id, DepListOpts{Types:[DepParentChild], Direction:In, UseWispsTable:useWisp}) returns a non-nil error, e.g. the issue ID does not exist, the database is unreachable, or the dependency table query fails.","commonSituations":"Querying a deleted/renamed issue ID in a script that counts open subtasks; Dolt database connection drops mid-query; schema mismatch when the wisps table flag (useWisp) selects a table that is missing or migrated.","solutions":["Inspect the wrapped error (%w chain) printed after 'CountOpenChildren <id>:' to find the root cause","Verify the issue ID exists (e.g. bd show <id>) before counting children","Check database connectivity and re-run; transient storage failures can be retried","If using the wisp path, confirm the wisps table exists and is migrated"],"exampleFix":"// before\nn, err := uc.CountOpenChildren(ctx, id, false)\nif err != nil { return err }\n// after\nn, err := uc.CountOpenChildren(ctx, id, false)\nif err != nil {\n    var nf *types.ErrNotFound\n    if errors.As(err, &nf) { return nil } // treat missing parent as zero children\n    return err\n}","handlingStrategy":"try-catch","validationCode":"if id == \"\" {\n    return 0, fmt.Errorf(\"cannot count children: empty issue id\")\n}","typeGuard":"func hasID(id string) bool { return strings.TrimSpace(id) != \"\" }","tryCatchPattern":"open, err := uc.CountOpenChildren(ctx, id, useWisp)\nif err != nil {\n    log.Warnf(\"child count unavailable for %s: %v\", id, err)\n    return -1 // or skip gracefully\n}","preventionTips":["Validate issue IDs exist before dependency queries","Use errors.As/errors.Is to inspect the wrapped root cause","Check DB connectivity before batch counting operations","Keep schema migrations current when using the wisps table"],"tags":["go","storage","error-wrapping","dependency-query"],"backgroundTag":"repository-query-failed","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}