siyuan-note/siyuan · error

invalid document spec

Error message

invalid document spec [%s]

What it means

CheckSpec validates a tree's Root.Spec after parsing it to an integer. This error means the spec string could not satisfy the minimum: parsing succeeded but the numeric spec is less than 1 (or the string is otherwise unusable as a positive spec).

Solutions

  1. Set Root.Spec to a valid positive integer <= CurrentSpec (e.g. "3") in the .sy JSON
  2. Restore the document from data history or a sync snapshot
  3. Regenerate the document (re-import) if the source file is corrupt
  4. Fix the external tool to always write a valid Spec field

Example fix

// before
{ "Root": { "Spec": "0", ... } }
// after
{ "Root": { "Spec": "3", ... } }
Defensive patterns

Strategy: validation

Validate before calling

const spec = parseInt(root.Spec, 10);
if (!(spec >= 1 && spec <= 4)) throw new Error(`invalid document spec ${root.Spec}`);

Prevention

When it happens

Trigger: Loading a .sy file whose Root.Spec is "0", negative, or a malformed-but-numeric value via CheckSpec called from NormalizeTreeForRead, prepareWriteTree, fixTreeJSONData, parseJSON2Tree, or CheckSpecJSON.

Common situations: Hand-edited or third-party-generated .sy JSON missing/zeroing Spec; corrupted files from interrupted writes; tools that create documents without setting Spec.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


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

Appendix: source

Thrown at kernel/treenode/tree.go:182

	}
	return checkTableCellRichJSON(data, root.Spec)
}

func CheckSpec(tree *parse.Tree) (err error) {
	if err = ValidateTableCellRich(tree.Root); nil != err {
		return
	}
	if CurrentSpec == tree.Root.Spec || "" == tree.Root.Spec {
		return
	}

	spec, err := strconv.Atoi(tree.Root.Spec)
	if nil != err {
		logging.LogErrorf("parse spec [%s] failed: %s", tree.Root.Spec, err)
		return
	}
	if 1 > spec {
		return fmt.Errorf("invalid document spec [%s]", tree.Root.Spec)
	}

	currentSpec, _ := strconv.Atoi(CurrentSpec)
	if spec > currentSpec {
		logging.LogErrorf("tree spec [%s] is newer than current spec [%s]", tree.Root.Spec, CurrentSpec)
		return ErrSpecTooNew
	}
	return
}

func UpgradeSpec(tree *parse.Tree) (upgraded bool) {
	oldSpec := tree.Root.Spec
	upgradeSpec1(tree)
	upgradeSpec2(tree)
	if "2" == tree.Root.Spec {
		ast.Walk(tree.Root, func(node *ast.Node, entering bool) ast.WalkStatus {
			if entering && (ast.NodeTabs == node.Type || ast.NodeTabItem == node.Type) {
				tree.Root.Spec = "3"

View on GitHub (pinned to 9f775e8a12)