{"record":{"id":"bdec121b0065e13e","repo":"siyuan-note/siyuan","slug":"unsupported-template-database-mode-s","errorCode":null,"errorMessage":"unsupported template database mode [%s]","messagePattern":"unsupported template database mode \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/template.go","lineNumber":353,"sourceCode":"\t\ttemplateExportNameAttr:      name,\n\t\ttemplateExportDirectoryAttr: directory,\n\t})\n\tif nil != err {\n\t\tlogging.LogErrorf(\"remember template export settings failed: %s\", err)\n\t\terr = nil\n\t}\n\treturn\n}\n\nfunc DocSaveAsTemplateInDirectory(id, name, directory string, overwrite bool, databaseMode TemplateDatabaseMode) (code int, err error) {\n\tif err = validateTemplateRelativePath(directory, true); err != nil {\n\t\treturn\n\t}\n\tif databaseMode == \"\" {\n\t\tdatabaseMode = TemplateDatabaseModeCopy\n\t}\n\tif TemplateDatabaseModeCopy != databaseMode && TemplateDatabaseModeReference != databaseMode {\n\t\treturn 0, fmt.Errorf(\"unsupported template database mode [%s]\", databaseMode)\n\t}\n\n\tbt := treenode.GetBlockTree(id)\n\tif nil == bt {\n\t\treturn\n\t}\n\n\ttree := prepareExportTree(bt)\n\ttree.Root.RemoveIALAttr(templateExportNameAttr)\n\ttree.Root.RemoveIALAttr(templateExportDirectoryAttr)\n\tmarkTemplateAttributeViewModes(tree.Root, databaseMode)\n\taddBlockIALNodes(tree, true)\n\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","sourceCodeStart":335,"sourceCodeEnd":371,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/template.go#L335-L371","documentation":"DocSaveAsTemplateInDirectory validates the databaseMode parameter for saving a document as a template: it must be TemplateDatabaseModeCopy or TemplateDatabaseModeReference (an empty string defaults to copy). Any other value yields a plain fmt.Errorf with the literal message \"unsupported template database mode [%s]\" naming the invalid value — a hardcoded, non-localized argument validation error.","triggerScenarios":"Calling DocSaveAsTemplateWithDatabaseMode / DocSaveAsTemplateInDirectoryAndRemember with databaseMode set to anything other than \"copy\" or \"reference\" (e.g. \"Copy\", \"none\", \"keep\", a localized string, or a stale value persisted by an older version in remembered attributes).","commonSituations":"Plugin/UI passing an unrecognized mode string; remembering the mode in attributes under an older enum spelling and replaying it after a kernel upgrade; manual API calls with guesswork values instead of the exported constants.","solutions":["Pass exactly TemplateDatabaseModeCopy (\"copy\") or TemplateDatabaseModeReference (\"reference\") from kernel/model template constants","Send empty string (or omit the field) to accept the default copy mode","Check remembered attributes (DocSaveAsTemplateInDirectoryAndRemember) for a stale mode value saved by an earlier version and clear/reset it","Match case exactly — the comparison is case-sensitive"],"exampleFix":"// before\nsaveAsTemplate(id, name, \"Copy\") // unsupported template database mode [Copy]\n// after\nsaveAsTemplate(id, name, model.TemplateDatabaseModeCopy) // \"copy\"","handlingStrategy":"validation","validationCode":"const VALID_MODES = new Set([\"copy\", \"reference\"]);\nif (databaseMode !== \"\" && !VALID_MODES.has(databaseMode)) {\n  throw new Error(`unsupported template database mode [${databaseMode}]`);\n}","typeGuard":"const isTemplateDatabaseMode = (v) => v === \"\" || v === \"copy\" || v === \"reference\";","tryCatchPattern":null,"preventionTips":["Always use the exported constants TemplateDatabaseModeCopy/Reference instead of string literals","Pass empty/undefined to get the default copy mode","Never persist localized or display strings as the mode value in remembered attributes","Match exact lowercase spelling — validation is case-sensitive"],"tags":["validation","api-parameter","template"],"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"}