siyuan-note/siyuan · error

unsupported template database mode

Error message

unsupported template database mode [%s]

What it means

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.

Solutions

  1. Pass exactly TemplateDatabaseModeCopy ("copy") or TemplateDatabaseModeReference ("reference") from kernel/model template constants
  2. Send empty string (or omit the field) to accept the default copy mode
  3. Check remembered attributes (DocSaveAsTemplateInDirectoryAndRemember) for a stale mode value saved by an earlier version and clear/reset it
  4. Match case exactly — the comparison is case-sensitive

Example fix

// before
saveAsTemplate(id, name, "Copy") // unsupported template database mode [Copy]
// after
saveAsTemplate(id, name, model.TemplateDatabaseModeCopy) // "copy"
Defensive patterns

Strategy: validation

Validate before calling

const VALID_MODES = new Set(["copy", "reference"]);
if (databaseMode !== "" && !VALID_MODES.has(databaseMode)) {
  throw new Error(`unsupported template database mode [${databaseMode}]`);
}

Type guard

const isTemplateDatabaseMode = (v) => v === "" || v === "copy" || v === "reference";

Prevention

When it happens

Trigger: 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).

Common situations: 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.

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/bdec121b0065e13e. Report an issue: GitHub.

Appendix: source

Thrown at kernel/model/template.go:353

		templateExportNameAttr:      name,
		templateExportDirectoryAttr: directory,
	})
	if nil != err {
		logging.LogErrorf("remember template export settings failed: %s", err)
		err = nil
	}
	return
}

func DocSaveAsTemplateInDirectory(id, name, directory string, overwrite bool, databaseMode TemplateDatabaseMode) (code int, err error) {
	if err = validateTemplateRelativePath(directory, true); err != nil {
		return
	}
	if databaseMode == "" {
		databaseMode = TemplateDatabaseModeCopy
	}
	if TemplateDatabaseModeCopy != databaseMode && TemplateDatabaseModeReference != databaseMode {
		return 0, fmt.Errorf("unsupported template database mode [%s]", databaseMode)
	}

	bt := treenode.GetBlockTree(id)
	if nil == bt {
		return
	}

	tree := prepareExportTree(bt)
	tree.Root.RemoveIALAttr(templateExportNameAttr)
	tree.Root.RemoveIALAttr(templateExportDirectoryAttr)
	markTemplateAttributeViewModes(tree.Root, databaseMode)
	addBlockIALNodes(tree, true)

	ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
		if !entering {
			return ast.WalkContinue
		}

View on GitHub (pinned to 9f775e8a12)