{"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":835,"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":817,"sourceCodeEnd":853,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L817-L853","documentation":"renderTemplateSource accepts only three render modes: Content, Preview, and EditorInsert. Any other TemplateRenderMode value is rejected up front with this error naming the offending mode. It prevents undefined behavior in mode-dependent code paths.","triggerScenarios":"Calling RenderTemplateWithMode (or anything reaching renderTemplateSource) with a mode string other than 'content', 'preview', or editor-insert — e.g. a typo, a raw user-supplied value, or an API caller inventing a mode.","commonSituations":"A plugin or script passing an arbitrary mode value through the kernel API; a frontend bug sending an empty or stale mode string; version drift where a mode constant was renamed.","solutions":["Pass one of the supported TemplateRenderMode constants (TemplateRenderModeContent, TemplateRenderModePreview, TemplateRenderModeEditorInsert).","Normalize/validate the mode string at the caller before invoking the renderer.","Log the offending value; if it comes from user input, clamp it to a default like Content."],"exampleFix":"// before\nrenderTemplateWithMode(id, \"preview \") // trailing space -> unsupported\n// after\nmode := strings.TrimSpace(modeInput)\nif mode != model.TemplateRenderModeContent && mode != model.TemplateRenderModePreview && mode != model.TemplateRenderModeEditorInsert {\n    mode = model.TemplateRenderModeContent\n}\nmodel.RenderTemplateWithMode(id, mode)","handlingStrategy":"validation","validationCode":"const VALID_MODES = [\"content\", \"preview\", \"editor-insert\"];\nif (!VALID_MODES.includes(mode)) throw new Error(`unsupported mode: ${mode}`)","typeGuard":"func validRenderMode(m string) bool {\n    switch m {\n    case TemplateRenderModeContent, TemplateRenderModePreview, TemplateRenderModeEditorInsert:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Always use the exported TemplateRenderMode constants, never raw strings","Trim and validate user-supplied mode input before calling the renderer"],"tags":["go","template","enum","invalid-argument"],"backgroundTag":"invalid-enum-value","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"}