siyuan-note/siyuan · error
createDocTree exceeds the maximum depth of
Error message
createDocTree exceeds the maximum depth of %d
What it means
parseNodes enforces maxTemplateDocTreeDepth (16) when recursing into nested 'children' arrays of the createDocTree definition. If the nesting level exceeds this limit, parsing aborts with a formatted error naming the maximum. This protects the kernel from deeply recursive definitions causing unbounded work.
Solutions
- Flatten or split the hierarchy so nesting stays within 16 levels; create additional root docs instead.
- Add a depth guard in the code that generates the definition and split oversized trees into multiple createDocTree calls.
- If depth 16 is genuinely needed, split the tree: create top levels first, then attach deeper subtrees under the newly created docs.
Example fix
// before
buildChildren(items, depth) // recurses unbounded, depth 20
// after
const MAX = 16;
if (depth > MAX) { splitIntoSeparateCall(items); return; } Defensive patterns
Strategy: validation
Validate before calling
function depthOf(def, d = 1) {
return def.reduce((m, n) => Math.max(m, Array.isArray(n.children) ? depthOf(n.children, d + 1) : d), d);
}
if (depthOf(def) > 16) throw new Error("definition exceeds max depth 16"); Try / catch
try {
await createDocTree(payload);
} catch (e) {
if (/exceeds the maximum depth/.test(String(e))) {
// split the tree into multiple calls rooted at shallower docs
} else { throw e; }
} Prevention
- Cap nesting depth in any generator producing the definition
- Prefer flattening hierarchies beyond ~10 levels for usability anyway
- Split very deep trees across multiple createDocTree invocations attached to intermediate docs
When it happens
Trigger: Submitting a createDocTree definition whose children arrays nest more than 16 levels deep, e.g. a generated outline with 17+ nested subsections.
Common situations: Programmatic generation of very deep document hierarchies (converted file trees, deeply nested mind maps); recursive generators without a depth cap; hand-built structures that grew over time.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- invalid rich clipboard asset count
- recursive template call
- 106
- 199
- active tab [ ] is not a direct child of [ ]
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/4cec3822c85b360d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:123
func parseTemplateDocTreeDefinition(def any) ([]*TemplateDocTreeNode, error) {
state := &templateDocTreeParseState{}
nodes, err := state.parseNodes(def, 1)
if nil != err {
return nil, err
}
if 0 == len(nodes) {
return nil, errors.New("createDocTree requires at least one document")
}
return nodes, nil
}
type templateDocTreeParseState struct {
count int
}
func (state *templateDocTreeParseState) parseNodes(value any, depth int) ([]*TemplateDocTreeNode, error) {
if maxTemplateDocTreeDepth < depth {
return nil, fmt.Errorf("createDocTree exceeds the maximum depth of %d", maxTemplateDocTreeDepth)
}
values, ok := value.([]any)
if !ok {
return nil, errors.New("createDocTree definition must be a list")
}
if 0 == len(values) {
return nil, errors.New("createDocTree document list must not be empty")
}
nodes := make([]*TemplateDocTreeNode, 0, len(values))
for _, value := range values {
definition, ok := value.(map[string]any)
if !ok {
return nil, errors.New("createDocTree document must be a dictionary")
}
for key := range definition {
switch key {
case "title", "template", "define", "children":View on GitHub (pinned to 9f775e8a12)