{"record":{"id":"76bdf75573550bf3","repo":"siyuan-note/siyuan","slug":"createdoctree-exceeds-the-maximum-document-count-o","errorCode":null,"errorMessage":"createDocTree exceeds the maximum document count of %d","messagePattern":"createDocTree exceeds the maximum document count of (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":177,"sourceCode":"\t\tif 512 < utf8.RuneCountInString(title) {\n\t\t\treturn nil, fmt.Errorf(\"createDocTree document title exceeds %d characters\", 512)\n\t\t}\n\n\t\ttemplateName, err := templateDocTreeStringField(definition, \"template\")\n\t\tif nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t\tdefineName, err := templateDocTreeStringField(definition, \"define\")\n\t\tif nil != err {\n\t\t\treturn nil, err\n\t\t}\n\t\tif \"\" != templateName && \"\" != defineName {\n\t\t\treturn nil, errors.New(\"createDocTree document template and define are mutually exclusive\")\n\t\t}\n\n\t\tstate.count++\n\t\tif maxTemplateDocTreeDocs < state.count {\n\t\t\treturn nil, fmt.Errorf(\"createDocTree exceeds the maximum document count of %d\", maxTemplateDocTreeDocs)\n\t\t}\n\t\tid := ast.NewNodeID()\n\t\tnode := &TemplateDocTreeNode{\n\t\t\tID:       id,\n\t\t\tRootID:   id,\n\t\t\tTitle:    title,\n\t\t\tDepth:    depth,\n\t\t\tTemplate: templateName,\n\t\t\tDefine:   defineName,\n\t\t}\n\t\tif childrenValue, exists := definition[\"children\"]; exists {\n\t\t\tchildren, parseErr := state.parseNodes(childrenValue, depth+1)\n\t\t\tif nil != parseErr {\n\t\t\t\treturn nil, parseErr\n\t\t\t}\n\t\t\tnode.Children = children\n\t\t}\n\t\tnodes = append(nodes, node)","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L159-L195","documentation":"A single createDocTree invocation is limited to maxTemplateDocTreeDocs (128) documents, counted across the whole definition tree. When parseNodes sees more than 128 entries in one definition, it aborts. The message interpolates the numeric limit.","triggerScenarios":"Passing a definition list (including all nested children at any depth) whose total document count exceeds 128. Raised from parseTemplateDocTreeDefinition during template insertion.","commonSituations":"Programmatically generating a large batch of documents (e.g. a year of daily notes = 365 entries); migrating a bulk import through createDocTree; deeply nested definitions that multiply entries.","solutions":["Split the definition into batches of at most 128 documents and invoke createDocTree multiple times.","Reduce generated entries (e.g. generate weekly rather than daily documents).","Generate documents via the kernel API in a loop instead of a single template action."],"exampleFix":"// before\ncreateDocTree(docs.slice(0, 300))\n// after\nfor (let i = 0; i < docs.length; i += 128) {\n  createDocTree(docs.slice(i, i + 128));\n}","handlingStrategy":"validation","validationCode":"function countDocs(nodes) {\n  return nodes.reduce((n, d) => n + 1 + (d.children ? countDocs(d.children) : 0), 0);\n}\nif (countDocs(def) > 128) throw new Error('split into batches of <= 128');","typeGuard":null,"tryCatchPattern":"try {\n  createDocTree(def);\n} catch (e) {\n  if (String(e).includes(\"maximum document count\")) {\n    for (let i = 0; i < def.length; i += 100) createDocTree(def.slice(i, i + 100));\n  }\n}","preventionTips":["Count nested children too when checking the 128 limit.","Batch large generated definitions into chunks under 128.","Prefer the kernel document API for bulk creation."],"tags":["template","limit","validation"],"backgroundTag":"value-out-of-range","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"}