{"record":{"id":"608a4ef29d00df46","repo":"siyuan-note/siyuan","slug":"invalid-heading-fold-scope","errorCode":null,"errorMessage":"invalid heading fold scope","messagePattern":"invalid heading fold scope","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/heading.go","lineNumber":61,"sourceCode":"\n\theading := treenode.GetNodeInTree(tree, id)\n\ttransaction = &Transaction{}\n\tif nil == heading || ast.NodeHeading != heading.Type {\n\t\treturn\n\t}\n\n\tvar headings []*ast.Node\n\tswitch scope {\n\tcase \"children\":\n\t\tif treenode.IsSelfFolded(heading) {\n\t\t\theadings = []*ast.Node{heading}\n\t\t} else {\n\t\t\theadings = treenode.HeadingDirectChildren(heading)\n\t\t}\n\tcase \"siblings\":\n\t\theadings = treenode.HeadingSiblings(heading)\n\tdefault:\n\t\terr = errors.New(\"invalid heading fold scope\")\n\t\treturn\n\t}\n\ttransaction = buildHeadingFoldTransaction(headings)\n\treturn\n}\n\nfunc buildHeadingFoldTransaction(headings []*ast.Node) (transaction *Transaction) {\n\ttransaction = &Transaction{}\n\tfoldAll := false\n\tfor _, heading := range headings {\n\t\tif !treenode.IsSelfFolded(heading) {\n\t\t\tfoldAll = true\n\t\t\tbreak\n\t\t}\n\t}\n\n\tfor i := len(headings) - 1; 0 <= i; i-- {\n\t\theading := headings[i]","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/heading.go#L43-L79","documentation":"GetHeadingFoldTransaction folds (or unfolds) a heading and computes the affected headings according to a scope argument. Only certain scope values (e.g. \"children\", \"siblings\", and the direct/recursive variants shown above) are recognized; any other string reaches the default branch and returns \"invalid heading fold scope\".","triggerScenarios":"Calling GetHeadingFoldTransaction(headingID, scope, isFold) with a scope value outside the enumerated set — a typo like \"child\" or \"subtree\", an empty string, or a scope name invented by a plugin.","commonSituations":"Frontend/plugin passes a user-configurable fold-scope option that doesn't match the kernel's enum; API consumers guessing scope names instead of reading the handler's allowed values.","solutions":["Use one of the supported scope values exactly (check the API handler for the accepted set, e.g. \"children\", \"siblings\")","Add a client-side allowlist of valid scope values before issuing the call","Catch the error and surface which scope string was rejected so the config can be fixed"],"exampleFix":"// before\ntransaction, err := model.GetHeadingFoldTransaction(id, scope, true) // scope from config\n// after\nvar validScopes = map[string]bool{\"children\": true, \"siblings\": true}\nif !validScopes[scope] {\n    return fmt.Errorf(\"unsupported fold scope %q\", scope)\n}\ntransaction, err := model.GetHeadingFoldTransaction(id, scope, true)","handlingStrategy":"validation","validationCode":"var validFoldScopes = map[string]bool{\"children\": true, \"siblings\": true}\nif !validFoldScopes[scope] {\n    return fmt.Errorf(\"fold scope %q not supported\", scope)\n}\ntransaction, err := model.GetHeadingFoldTransaction(headingID, scope, isFold)","typeGuard":"func validScope(s string) bool {\n    switch s {\n    case \"children\", \"siblings\":\n        return true\n    }\n    return false\n}","tryCatchPattern":"transaction, err := model.GetHeadingFoldTransaction(id, scope, fold)\nif err != nil && strings.Contains(err.Error(), \"invalid heading fold scope\") {\n    return fmt.Errorf(\"scope %q rejected; check API docs for allowed values\", scope)\n}","preventionTips":["Copy the scope strings from the kernel handler into a shared constant list","Constrain user-configurable fold options to the known enum via a dropdown, not free text","Log the rejected scope value to speed up config fixes"],"tags":["heading","enum","validation"],"backgroundTag":"invalid-enum-value","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}