siyuan-note/siyuan · error
createDocTree requires at least one document
Error message
createDocTree requires at least one document
What it means
parseTemplateDocTreeDefinition parses the createDocTree definition (a nested list/dictionary structure declaring child documents). After recursively parsing nodes it requires at least one document node at the top level; a definition that parses to an empty node list is rejected. Empty lists are also rejected earlier inside parseNodes.
Solutions
- Include at least one document object, e.g. [{"title": "Child doc"}].
- If def is nil or empty in your client, skip the createDocTree call instead of sending an empty plan.
- Check that your serialization of the tree definition is not dropping nodes (e.g. wrong JSON field name).
Example fix
// before
{"def": []}
// after
{"def": [{"title": "Chapter 1"}]} Defensive patterns
Strategy: validation
Validate before calling
function hasAtLeastOneDoc(def) {
return Array.isArray(def) && def.length > 0;
}
if (!hasAtLeastOneDoc(def)) return; // skip the call instead of sending an empty plan Try / catch
try {
await createDocTree(payload);
} catch (e) {
if (String(e).includes("at least one document")) {
// treat as no-op: nothing to create
} else { throw e; }
} Prevention
- Guard client code to skip createDocTree when the user added no documents
- Assert the serialized definition contains >= 1 node before sending
- Check that your node serialization isn't dropping everything (wrong field names)
When it happens
Trigger: Calling createDocTree with def = nil, def = [] (JSON empty array), or a value that yields zero nodes (e.g. an empty string form that was normalized to an empty list) so len(nodes)==0 after parseNodes returns.
Common situations: Frontend submitting the doc-tree dialog with no documents added; programmatically building the definition and forgetting to append the first node; an API consumer sending an empty array to 'validate' a request.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- AI editor input is empty
- asset data is empty
- at least one asset path or mapping is required
- Conf.Language(294)
- createDocTree document list must not be empty
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/e3f2cab7af01efa6.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template_doc_tree.go:112
nodes []*TemplateDocTreeNode
enabled bool
allowCreation bool
totalOutput int
}
var (
templateDocTreePlans sync.Map
templateDocTreePlansLock sync.Mutex
)
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")View on GitHub (pinned to 9f775e8a12)