{"record":{"id":"423a64b6825f7068","repo":"siyuan-note/siyuan","slug":"createdoctree-document-title-exceeds-d-characters","errorCode":null,"errorMessage":"createDocTree document title exceeds %d characters","messagePattern":"createDocTree document title exceeds (.+?) characters","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template_doc_tree.go","lineNumber":160,"sourceCode":"\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\")\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}","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template_doc_tree.go#L142-L178","documentation":"Document titles longer than 512 Unicode characters (counted in runes after normalization) are rejected. This cap keeps generated paths within filesystem and UX limits, since the title becomes a path segment of the created document.","triggerScenarios":"Calling createDocTree with a document whose title contains 513+ characters, e.g. a whole paragraph pasted as a title or generated titles built from long content.","commonSituations":"Using the first line of imported content as a title; automated pipelines copying long headings; concatenating fields into a title without truncation.","solutions":["Shorten the title to 512 or fewer characters (rune-aware truncation, not byte truncation, for CJK text).","Truncate programmatically at build time: cut to N runes and append an ellipsis or suffix while staying under the cap.","Move long text into the document body/template content and keep only a short summary as the title.","Pre-validate utf8.RuneCountInString(title) <= 512 before rendering."],"exampleFix":"// before\n{\"title\": veryLongParagraph} // 800 runes\n// after\n{\"title\": truncateRunes(veryLongParagraph, 512)}","handlingStrategy":"validation","validationCode":"func truncateRunes(s string, n int) string {\n    r := []rune(s)\n    if len(r) <= n { return s }\n    return string(r[:n])\n}\n// apply: def[\"title\"] = truncateRunes(title, 512)","typeGuard":"func titleWithinLimit(v any) bool {\n    m, ok := v.(map[string]any)\n    if !ok { return false }\n    t, ok := m[\"title\"].(string)\n    return ok && utf8.RuneCountInString(t) <= 512\n}","tryCatchPattern":"nodes, err := parseTemplateDocTreeDefinition(def)\nif err != nil {\n    if strings.Contains(err.Error(), \"title exceeds\") {\n        // truncate the reported title to 512 runes and retry\n    }\n    return err\n}","preventionTips":["Truncate titles rune-aware (not byte-aware) to stay correct with CJK/emoji text.","Keep long content in the document body; use short summary titles.","Check RuneCountInString <= 512 in template linting."],"tags":["template","length-limit","title"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}