siyuan-note/siyuan · error
invalid heading fold scope
Error message
invalid heading fold scope
What it means
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".
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
Example fix
// before
transaction, err := model.GetHeadingFoldTransaction(id, scope, true) // scope from config
// after
var validScopes = map[string]bool{"children": true, "siblings": true}
if !validScopes[scope] {
return fmt.Errorf("unsupported fold scope %q", scope)
}
transaction, err := model.GetHeadingFoldTransaction(id, scope, true) Defensive patterns
Strategy: validation
Validate before calling
var validFoldScopes = map[string]bool{"children": true, "siblings": true}
if !validFoldScopes[scope] {
return fmt.Errorf("fold scope %q not supported", scope)
}
transaction, err := model.GetHeadingFoldTransaction(headingID, scope, isFold) Type guard
func validScope(s string) bool {
switch s {
case "children", "siblings":
return true
}
return false
} Try / catch
transaction, err := model.GetHeadingFoldTransaction(id, scope, fold)
if err != nil && strings.Contains(err.Error(), "invalid heading fold scope") {
return fmt.Errorf("scope %q rejected; check API docs for allowed values", scope)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- cannot swap a heading with a block in its section
- ErrInvalidColumnAlign
- Field [mode] must be 0 or 1
- Field [ ] has an invalid value
- invalid asset download mode
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/608a4ef29d00df46.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/heading.go:61
heading := treenode.GetNodeInTree(tree, id)
transaction = &Transaction{}
if nil == heading || ast.NodeHeading != heading.Type {
return
}
var headings []*ast.Node
switch scope {
case "children":
if treenode.IsSelfFolded(heading) {
headings = []*ast.Node{heading}
} else {
headings = treenode.HeadingDirectChildren(heading)
}
case "siblings":
headings = treenode.HeadingSiblings(heading)
default:
err = errors.New("invalid heading fold scope")
return
}
transaction = buildHeadingFoldTransaction(headings)
return
}
func buildHeadingFoldTransaction(headings []*ast.Node) (transaction *Transaction) {
transaction = &Transaction{}
foldAll := false
for _, heading := range headings {
if !treenode.IsSelfFolded(heading) {
foldAll = true
break
}
}
for i := len(headings) - 1; 0 <= i; i-- {
heading := headings[i]View on GitHub (pinned to 9f775e8a12)