{"record":{"id":"825982439f37cceb","repo":"siyuan-note/siyuan","slug":"invalid-document-spec-s","errorCode":null,"errorMessage":"invalid document spec [%s]","messagePattern":"invalid document spec \\[(.+?)\\]","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/treenode/tree.go","lineNumber":182,"sourceCode":"\t}\n\treturn checkTableCellRichJSON(data, root.Spec)\n}\n\nfunc CheckSpec(tree *parse.Tree) (err error) {\n\tif err = ValidateTableCellRich(tree.Root); nil != err {\n\t\treturn\n\t}\n\tif CurrentSpec == tree.Root.Spec || \"\" == tree.Root.Spec {\n\t\treturn\n\t}\n\n\tspec, err := strconv.Atoi(tree.Root.Spec)\n\tif nil != err {\n\t\tlogging.LogErrorf(\"parse spec [%s] failed: %s\", tree.Root.Spec, err)\n\t\treturn\n\t}\n\tif 1 > spec {\n\t\treturn fmt.Errorf(\"invalid document spec [%s]\", tree.Root.Spec)\n\t}\n\n\tcurrentSpec, _ := strconv.Atoi(CurrentSpec)\n\tif spec > currentSpec {\n\t\tlogging.LogErrorf(\"tree spec [%s] is newer than current spec [%s]\", tree.Root.Spec, CurrentSpec)\n\t\treturn ErrSpecTooNew\n\t}\n\treturn\n}\n\nfunc UpgradeSpec(tree *parse.Tree) (upgraded bool) {\n\toldSpec := tree.Root.Spec\n\tupgradeSpec1(tree)\n\tupgradeSpec2(tree)\n\tif \"2\" == tree.Root.Spec {\n\t\tast.Walk(tree.Root, func(node *ast.Node, entering bool) ast.WalkStatus {\n\t\t\tif entering && (ast.NodeTabs == node.Type || ast.NodeTabItem == node.Type) {\n\t\t\t\ttree.Root.Spec = \"3\"","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/treenode/tree.go#L164-L200","documentation":"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).","triggerScenarios":"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.","commonSituations":"Hand-edited or third-party-generated .sy JSON missing/zeroing Spec; corrupted files from interrupted writes; tools that create documents without setting Spec.","solutions":["Set Root.Spec to a valid positive integer <= CurrentSpec (e.g. \"3\") in the .sy JSON","Restore the document from data history or a sync snapshot","Regenerate the document (re-import) if the source file is corrupt","Fix the external tool to always write a valid Spec field"],"exampleFix":"// before\n{ \"Root\": { \"Spec\": \"0\", ... } }\n// after\n{ \"Root\": { \"Spec\": \"3\", ... } }","handlingStrategy":"validation","validationCode":"const spec = parseInt(root.Spec, 10);\nif (!(spec >= 1 && spec <= 4)) throw new Error(`invalid document spec ${root.Spec}`);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always write a valid positive Spec when generating .sy files","Validate JSON of externally generated documents before importing","Restore corrupted files from history instead of hand-editing Spec"],"tags":["validation","document-spec","corruption"],"backgroundTag":"invalid-argument-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"}