{"record":{"id":"352a8c51cfe08923","repo":"siyuan-note/siyuan","slug":"createdoctree-document-list-must-not-be-empty","errorCode":null,"errorMessage":"createDocTree document list must not be empty","messagePattern":"createDocTree document list must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":130,"sourceCode":"\t\treturn nil, errors.New(\"createDocTree requires at least one document\")\n\t}\n\treturn nodes, nil\n}\n\ntype templateDocTreeParseState struct {\n\tcount int\n}\n\nfunc (state *templateDocTreeParseState) parseNodes(value any, depth int) ([]*TemplateDocTreeNode, error) {\n\tif maxTemplateDocTreeDepth < depth {\n\t\treturn nil, fmt.Errorf(\"createDocTree exceeds the maximum depth of %d\", maxTemplateDocTreeDepth)\n\t}\n\tvalues, ok := value.([]any)\n\tif !ok {\n\t\treturn nil, errors.New(\"createDocTree definition must be a list\")\n\t}\n\tif 0 == len(values) {\n\t\treturn nil, errors.New(\"createDocTree document list must not be empty\")\n\t}\n\n\tnodes := make([]*TemplateDocTreeNode, 0, len(values))\n\tfor _, value := range values {\n\t\tdefinition, ok := value.(map[string]any)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"createDocTree document must be a dictionary\")\n\t\t}\n\t\tfor key := range definition {\n\t\t\tswitch key {\n\t\t\tcase \"title\", \"template\", \"define\", \"children\":\n\t\t\tdefault:\n\t\t\t\treturn nil, fmt.Errorf(\"createDocTree document contains unknown field [%s]\", key)\n\t\t\t}\n\t\t}\n\n\t\ttitleValue, ok := definition[\"title\"]\n\t\tif !ok {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L112-L148","documentation":"After confirming the definition level is a list, parseNodes rejects an empty list. Every list in the createDocTree definition (top level and nested children) must contain at least one document dictionary; an empty children array at any level triggers this error.","triggerScenarios":"Calling createDocTree with def = [] or with a node whose \"children\" key is set to [] instead of being omitted.","commonSituations":"UI form where the user cleared all rows; generator code that always emits a children key even when there are no children; template placeholders left unfilled.","solutions":["Remove the empty \"children\" key from nodes without children; only include children when the list is non-empty.","Add at least one document object to the top-level list.","In generating code, omit children arrays of length 0 instead of serializing them."],"exampleFix":"// before\n[{\"title\": \"Doc\", \"children\": []}]\n// after\n[{\"title\": \"Doc\"}]","handlingStrategy":"validation","validationCode":"function pruneEmptyChildren(nodes) {\n  return nodes.map(n => {\n    const out = { ...n };\n    if (Array.isArray(out.children)) {\n      if (out.children.length === 0) delete out.children;\n      else out.children = pruneEmptyChildren(out.children);\n    }\n    return out;\n  });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit the children key when a node has no children instead of sending []","Prune empty arrays from generated definitions before submission","Top-level definitions must contain at least one document object"],"tags":["empty-input","validation","json"],"backgroundTag":"empty-required-field","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"}