{"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/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template_doc_tree.go#L131-L167","documentation":"Every document object in a createDocTree definition must contain a title field; it is the only mandatory key because it becomes the child document's name/path segment. Missing title causes this error before any document is created.","triggerScenarios":"A document object with only template or define, e.g. {\"template\": \"note.md\"}; a children entry that forgot the title key; generated definitions where the title key was dropped by serialization.","commonSituations":"Authors assuming the template file name is used as the title; destructuring/serialization losing empty or absent keys; LLM-generated templates omitting title on child nodes.","solutions":["Add a title field to every document object in the definition.","If the title should come from the template, still supply an explicit title string and let the template content provide the body.","Check any code that builds definitions dynamically to always set title (fall back to a generated name if needed).","Validate with a schema check requiring title:string on each node before rendering."],"exampleFix":"// before\n{\"template\": \"meeting.md\", \"children\": [{\"define\": \"daily\"}]}\n// after\n{\"title\": \"Meeting\", \"template\": \"meeting.md\", \"children\": [{\"title\": \"Daily\", \"define\": \"daily\"}]}","handlingStrategy":"validation","validationCode":"var walk func(nodes []any) error\nwalk = func(nodes []any) error {\n    for _, v := range nodes {\n        m, ok := v.(map[string]any)\n        if !ok { continue }\n        if _, ok := m[\"title\"]; !ok {\n            return errors.New(\"every document needs a title field\")\n        }\n        if c, ok := m[\"children\"]; ok {\n            if cl, ok := c.([]any); ok {\n                if err := walk(cl); err != nil { return err }\n            }\n        }\n    }\n    return nil\n}","typeGuard":"func hasTitle(v any) bool {\n    m, ok := v.(map[string]any)\n    if !ok { return false }\n    _, ok = m[\"title\"]\n    return ok\n}","tryCatchPattern":"nodes, err := parseTemplateDocTreeDefinition(def)\nif err != nil {\n    if strings.Contains(err.Error(), \"title is required\") {\n        // add a title (or derive one from the template file name) and retry\n    }\n    return err\n}","preventionTips":["Treat title as mandatory on every node, even when template or define supplies content.","In generators, always set title with a fallback default name.","Lint definitions for the presence of title on all nodes."],"tags":["template","missing-field","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}