{"record":{"id":"e3251d03e7ec6e6b","repo":"siyuan-note/siyuan","slug":"parse-tree-s-failed-e3251d","errorCode":null,"errorMessage":"parse tree [%s] failed","messagePattern":"parse tree \\[(.+?)\\] failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":425,"sourceCode":"\tgoTpl = goTpl.Funcs(tplFuncMap)\n\ttpl, err := goTpl.Funcs(tplFuncMap).Parse(gulu.Str.FromBytes(md))\n\tif err != nil {\n\t\terr = fmt.Errorf(Conf.Language(44), err.Error())\n\t\treturn\n\t}\n\n\tbuf := &bytes.Buffer{}\n\tbuf.Grow(4096)\n\tif err = tpl.Execute(buf, dataModel); err != nil {\n\t\terr = fmt.Errorf(Conf.Language(44), err.Error())\n\t\treturn\n\t}\n\tmd = buf.Bytes()\n\ttree = parseKTree(md)\n\tif nil == tree {\n\t\tmsg := fmt.Sprintf(\"parse tree [%s] failed\", p)\n\t\tlogging.LogError(msg)\n\t\terr = errors.New(msg)\n\t\treturn\n\t}\n\n\tvar nodesNeedAppendChild, unlinks []*ast.Node\n\t// 模板内部块旧 ID 到新 ID 的映射，用于成套改写模板内部的自引用\n\tblockIDs := map[string]string{}\n\tast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {\n\t\tif !entering {\n\t\t\treturn ast.WalkContinue\n\t\t}\n\n\t\tif \"\" != n.ID {\n\t\t\t// 重新生成 ID，并记录旧 ID 到新 ID 的映射，用于后续成套改写模板内部的自引用\n\t\t\toldID := n.ID\n\t\t\tn.ID = ast.NewNodeID()\n\t\t\tblockIDs[oldID] = n.ID\n\t\t\tn.SetIALAttr(\"id\", n.ID)\n\t\t\tn.RemoveIALAttr(av.NodeAttrNameAvs)","sourceCodeStart":407,"sourceCodeEnd":443,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/model/template.go#L407-L443","documentation":"Returned by RenderTemplate (template.go:425) when the template executed successfully but the resulting markdown bytes could not be parsed into a Lute/Kramdown tree by parseKTree(md). This is a post-render integrity failure: the template produced output that is not valid SiYuan markdown/Kramdown.","triggerScenarios":"A template that, after .action{} substitution, yields malformed Kramdown: unclosed block-level constructs, invalid IAL syntax ({: id=...} malformed), broken block-reference syntax, or raw HTML/structures the Lute parser rejects. The error is logged via logging.LogError and returned as errors.New(msg) with the template path 'p' interpolated.","commonSituations":"A template emits a partial IAL block like {: id= (missing value/close); a template concatenates block IDs incorrectly producing invalid reference syntax; a template outputs binary or non-markdown content; a template that worked under an older Lute version breaks after a Lute upgrade.","solutions":["Capture the executed markdown output (buf.Bytes()) before parseKTree and inspect it for malformed Kramdown — add a debug log or write to a temp file.","Fix the template so its output is well-formed Kramdown/markdown: balance IAL blocks {: ... }, close all block constructs, escape raw control characters.","If using block-ID substitution (the code below remaps IDs via ast.Walk), ensure generated IDs match the 20-char node-ID pattern.","Reproduce by feeding the rendered markdown into a standalone Lute parse to get the exact Lute error."],"exampleFix":"// before — template emits broken IAL\n.action{.id}{: id=\n\n// after — well-formed IAL\n.action{.id}{: id=\"20240101000000abcdef\"}","handlingStrategy":"validation","validationCode":"// After rendering template markdown, validate it parses as Kramdown before relying on the tree\nmd := renderedBytes\nif tree := parseKTree(md); tree == nil {\n    return fmt.Errorf(\"rendered template output is not valid Kramdown: %s\", string(md))\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Inspect rendered markdown output (buf.Bytes()) when debugging — the failure is in the OUTPUT, not the template syntax.","Ensure IAL blocks {: id=\"...\"} are well-formed with quoted values.","Avoid emitting raw control characters or partial block constructs from templates."],"tags":["template","lute","kramdown","parsing","ast"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}