{"record":{"id":"27841e1aef37fe45","repo":"siyuan-note/siyuan","slug":"createdoctree-document-title-is-required","errorCode":null,"errorMessage":"createDocTree document title is required","messagePattern":"createDocTree document title is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":149,"sourceCode":"\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 {\n\t\t\treturn nil, errors.New(\"createDocTree document title is required\")\n\t\t}\n\t\ttitle, ok := titleValue.(string)\n\t\tif !ok {\n\t\t\treturn nil, errors.New(\"createDocTree document title must be a string\")\n\t\t}\n\t\ttitle = normalizeDocTitle(title)\n\t\tif \"\" == title {\n\t\t\treturn nil, errors.New(\"createDocTree document title must not be empty\")\n\t\t}\n\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\")","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template_doc_tree.go#L131-L167","documentation":"Every document entry in a createDocTree definition must carry a title field, which becomes the child document's name and hierarchical path segment. parseNodes throws this when the title key is absent from a document object. Without a title the kernel cannot place the new document in the tree.","triggerScenarios":"A document object in the createDocTree list omits \"title\" entirely, e.g. {\"template\": \"tpl.md\"} or {\"children\": [...]}. Triggered via parseTemplateDocTreeDefinition when a template is manually inserted in the editor.","commonSituations":"Templates that only specify content template/define assuming a title is auto-derived; programmatically generated definition lists missing the title key; templates copied from examples that showed title as optional.","solutions":["Add a \"title\" string field to every document object in the createDocTree definition.","Verify each entry in the list (including nested children entries) has title.","If the title should come from rendered content, compute it in the template before invoking createDocTree."],"exampleFix":"// before\n[{\"template\": \"daily.md\", \"children\": []}]\n// after\n[{\"title\": \"2026-09-18\", \"template\": \"daily.md\", \"children\": []}]","handlingStrategy":"validation","validationCode":"function hasTitle(doc) {\n  return typeof doc.title === \"string\";\n}\nconst ok = docs.every(d => hasTitle(d));","typeGuard":"const isDocWithTitle = (d) => typeof d === 'object' && d !== null && typeof d.title === 'string';","tryCatchPattern":null,"preventionTips":["Always include title in every document entry, including nested children.","Validate the whole definition list before invoking createDocTree.","Never assume title is optional."],"tags":["template","validation","missing-field"],"backgroundTag":"missing-required-argument","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"}