{"record":{"id":"00189626843bb47d","repo":"siyuan-note/siyuan","slug":"unsupported-template-render-mode-s","errorCode":null,"errorMessage":"unsupported template render mode [%s]","messagePattern":"unsupported template render mode \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":751,"sourceCode":"}\n\nfunc RenderTemplateWithMode(p, id string, mode TemplateRenderMode) (tree *parse.Tree, dom string,\n\tsummary *TemplateDocTreePlanSummary, err error) {\n\treturn renderTemplateSource(p, id, mode, nil)\n}\n\n// 编辑器预览使用未保存的源码，文件路径仅用于解析同包子模板。\nfunc PreviewTemplateSource(p, id, content string) (tree *parse.Tree, dom string, summary *TemplateDocTreePlanSummary, err error) {\n\tif len(content) > maxTemplateSourceSize {\n\t\treturn nil, \"\", nil, errors.New(\"template source is too large\")\n\t}\n\treturn renderTemplateSource(p, id, TemplateRenderModePreview, &content)\n}\n\nfunc renderTemplateSource(p, id string, mode TemplateRenderMode, content *string) (tree *parse.Tree, dom string,\n\tsummary *TemplateDocTreePlanSummary, err error) {\n\tif TemplateRenderModeContent != mode && TemplateRenderModePreview != mode && TemplateRenderModeEditorInsert != mode {\n\t\terr = fmt.Errorf(\"unsupported template render mode [%s]\", mode)\n\t\treturn\n\t}\n\tpreview := TemplateRenderModePreview == mode\n\ttree, err = LoadTreeByBlockID(id)\n\tif err != nil {\n\t\treturn\n\t}\n\tsourceTree := tree\n\n\tnode := treenode.GetNodeInTree(tree, id)\n\tif nil == node {\n\t\terr = ErrBlockNotFound\n\t\treturn\n\t}\n\tblock := sql.BuildBlockFromNode(node, tree)\n\tvar md []byte\n\tif content == nil {\n\t\tmd, err = os.ReadFile(p)","sourceCodeStart":733,"sourceCodeEnd":769,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/template.go#L733-L769","documentation":"renderTemplateSource only accepts three render modes: Content, Preview, and EditorInsert. Any other TemplateRenderMode value is rejected before any parsing happens. This is an argument validation error for an enum-like mode parameter.","triggerScenarios":"Calling renderTemplateSource (directly or via a new wrapper) with a mode value other than TemplateRenderModeContent, TemplateRenderModePreview, or TemplateRenderModeEditorInsert — e.g. a newly added mode constant not yet whitelisted here, or an uninitialized/zero-value mode.","commonSituations":"Developer adds a new render mode constant and forgets to update the switch in renderTemplateSource; caller passes an empty string or stale mode value from config; test code using an invalid mode.","solutions":["Pass one of the supported modes: TemplateRenderModeContent, TemplateRenderModePreview, or TemplateRenderModeEditorInsert","If a new mode is needed, add it to the validation condition in renderTemplateSource (kernel/model/template.go:752)","Initialize the mode variable explicitly instead of relying on the zero value"],"exampleFix":"// before\nrenderTemplateSource(p, id, \"custom-mode\", &content)\n// after\nrenderTemplateSource(p, id, model.TemplateRenderModePreview, &content)","handlingStrategy":"validation","validationCode":"switch mode {\ncase model.TemplateRenderModeContent, model.TemplateRenderModePreview, model.TemplateRenderModeEditorInsert:\n    // ok\ndefault:\n    return errors.New(\"unsupported render mode\")\n}","typeGuard":"func validRenderMode(m model.TemplateRenderMode) bool {\n    return m == model.TemplateRenderModeContent || m == model.TemplateRenderModePreview || m == model.TemplateRenderModeEditorInsert\n}","tryCatchPattern":"tree, _, _, err := RenderTemplateWithMode(p, id, mode)\nif err != nil && strings.Contains(err.Error(), \"unsupported template render mode\") {\n    mode = model.TemplateRenderModeContent // retry with default\n}","preventionTips":["Only pass the exported TemplateRenderMode constants","Update renderTemplateSource's whitelist when adding new modes","Never pass empty strings or raw user input as the mode"],"tags":["go","template","invalid-argument","enum"],"backgroundTag":"invalid-enum-value","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"}