{"record":{"id":"b5a2bdc2a997d151","repo":"gastownhall/beads","slug":"max-depth-must-be-at-least-1-got-d","errorCode":null,"errorMessage":"max depth must be at least 1, got %d","messagePattern":"max depth must be at least 1, got (.+?)","errorType":"validation","errorClass":"publicops.ErrValidation","httpStatus":null,"severity":"error","filePath":"internal/storage/issueops/tree_walk.go","lineNumber":41,"sourceCode":"// issueops.WalkTreeRequest documents and returns the normalized direction. It is\n// pure and shared so that all three backends refuse in the same words.\nfunc ValidateWalkTreeRequest(req publicops.WalkTreeRequest) (publicops.TreeDirection, error) {\n\tif req.RootID == \"\" {\n\t\treturn \"\", fmt.Errorf(\"%w: root id must not be empty\", publicops.ErrValidation)\n\t}\n\tdirection := req.Direction\n\tif direction == \"\" {\n\t\tdirection = publicops.TreeDown\n\t}\n\tswitch direction {\n\tcase publicops.TreeDown, publicops.TreeUp, publicops.TreeBoth:\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"%w: direction %q must be one of %q, %q, %q\",\n\t\t\tpublicops.ErrValidation, req.Direction,\n\t\t\tpublicops.TreeDown, publicops.TreeUp, publicops.TreeBoth)\n\t}\n\tif req.MaxDepth < 1 {\n\t\treturn \"\", fmt.Errorf(\"%w: max depth must be at least 1, got %d\", publicops.ErrValidation, req.MaxDepth)\n\t}\n\tif req.MaxRows < 0 {\n\t\treturn \"\", fmt.Errorf(\"%w: max rows must not be negative, got %d\", publicops.ErrValidation, req.MaxRows)\n\t}\n\treturn direction, nil\n}\n\n// PruneTreeByStatus keeps every node carrying status, plus the ancestor chain of\n// each survivor, in the walk order the nodes arrived in.\n//\n// KEEPING THE ANCESTORS IS WHAT MAKES THE ANSWER STILL A TREE. A bare filter\n// would return nodes whose ParentID names something absent from the answer, and\n// every renderer that rebuilds the shape from Depth and ParentID would then draw\n// orphans at the wrong indentation.\n//\n// A PRUNE THAT MATCHES NOTHING RETURNS NOTHING, root included. The root survives\n// only as somebody's ancestor, never for its own sake, so a tree with no\n// matching member comes back empty rather than as a lone root — see","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/storage/issueops/tree_walk.go#L23-L59","documentation":"ValidateWalkTreeRequest requires MaxDepth to be at least 1; zero or negative values are rejected with this ErrValidation-wrapped error. The library throws it because a depth of 0 would visit no nodes, which cannot be a meaningful traversal, so the caller must explicitly request at least one level.","triggerScenarios":"Calling WalkDependencyTreeInTx with req.MaxDepth == 0 (e.g. an uninitialized struct) or negative (e.g. -1 from a misparsed flag or a \"no limit\" sentinel).","commonSituations":"Leaving MaxDepth unset on a zero-value struct; using 0 to mean \"unlimited\" from another library's convention; parsing an optional --depth flag whose default is 0.","solutions":["Set req.MaxDepth to a positive integer reflecting how deep you want to walk.","If the field was left at its zero value, initialize it explicitly (e.g. a sensible default like 10).","If you intended unlimited depth, pass a large finite value the library accepts, since 0 is invalid here.","Fix flag/config parsing so missing depth maps to a positive default, not 0."],"exampleFix":"// before\nreq := publicops.WalkDependencyTreeRequest{IssueID: id} // MaxDepth = 0\n// after\nreq := publicops.WalkDependencyTreeRequest{IssueID: id, MaxDepth: 10}","handlingStrategy":"validation","validationCode":"if req.MaxDepth < 1 {\n\treturn fmt.Errorf(\"MaxDepth must be >= 1, got %d\", req.MaxDepth)\n}","typeGuard":null,"tryCatchPattern":"if err := walk(ctx, req); errors.Is(err, publicops.ErrValidation) {\n\t// correct MaxDepth before retrying\n}","preventionTips":["Never construct the request with a bare struct literal without setting MaxDepth.","Clamp parsed flag/config values to >= 1 at the boundary.","Add a helper constructor that applies a default MaxDepth."],"tags":["validation","dependency-tree","parameter-range"],"backgroundTag":"parameter-out-of-range","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}