siyuan-note/siyuan · error
unsupported template render mode
Error message
unsupported template render mode [%s]
What it means
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.
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.
Example fix
// before
renderTemplateWithMode(id, "preview ") // trailing space -> unsupported
// after
mode := strings.TrimSpace(modeInput)
if mode != model.TemplateRenderModeContent && mode != model.TemplateRenderModePreview && mode != model.TemplateRenderModeEditorInsert {
mode = model.TemplateRenderModeContent
}
model.RenderTemplateWithMode(id, mode) Defensive patterns
Strategy: validation
Validate before calling
const VALID_MODES = ["content", "preview", "editor-insert"];
if (!VALID_MODES.includes(mode)) throw new Error(`unsupported mode: ${mode}`) Type guard
func validRenderMode(m string) bool {
switch m {
case TemplateRenderModeContent, TemplateRenderModePreview, TemplateRenderModeEditorInsert:
return true
}
return false
} Prevention
- Always use the exported TemplateRenderMode constants, never raw strings
- Trim and validate user-supplied mode input before calling the renderer
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- unsupported renderDocRef query mode
- attribute view [ ] not found in box [ ]
- attribute view [ ] template plan not found
- child template definition
- child template [ ] not found in the current template package
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/00189626843bb47d.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/template.go:835
}
func RenderTemplateWithMode(p, id string, mode TemplateRenderMode) (tree *parse.Tree, dom string,
summary *TemplateDocTreePlanSummary, err error) {
return renderTemplateSource(p, id, mode, nil)
}
// 编辑器预览使用未保存的源码,文件路径仅用于解析同包子模板。
func PreviewTemplateSource(p, id, content string) (tree *parse.Tree, dom string, summary *TemplateDocTreePlanSummary, err error) {
if len(content) > maxTemplateSourceSize {
return nil, "", nil, errors.New("template source is too large")
}
return renderTemplateSource(p, id, TemplateRenderModePreview, &content)
}
func renderTemplateSource(p, id string, mode TemplateRenderMode, content *string) (tree *parse.Tree, dom string,
summary *TemplateDocTreePlanSummary, err error) {
if TemplateRenderModeContent != mode && TemplateRenderModePreview != mode && TemplateRenderModeEditorInsert != mode {
err = fmt.Errorf("unsupported template render mode [%s]", mode)
return
}
preview := TemplateRenderModePreview == mode
tree, err = LoadTreeByBlockID(id)
if err != nil {
return
}
sourceTree := tree
node := treenode.GetNodeInTree(tree, id)
if nil == node {
err = ErrBlockNotFound
return
}
block := sql.BuildBlockFromNode(node, tree)
var md []byte
if content == nil {
md, err = os.ReadFile(p)View on GitHub (pinned to 9f775e8a12)