{"record":{"id":"ee38d4f754aef503","repo":"siyuan-note/siyuan","slug":"cannot-parse-document-s-v","errorCode":null,"errorMessage":"cannot parse document %s: %v","messagePattern":"cannot parse document (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/asset_relink.go","lineNumber":188,"sourceCode":"\t\t\t\treturn fmt.Errorf(\"invalid document JSON: %s\", absPath)\n\t\t\t}\n\t\t\tvar header struct {\n\t\t\t\tID         string `json:\"ID\"`\n\t\t\t\tProperties struct {\n\t\t\t\t\tTitle string `json:\"title\"`\n\t\t\t\t} `json:\"Properties\"`\n\t\t\t}\n\t\t\tif readErr = json.Unmarshal(data, &header); readErr != nil {\n\t\t\t\treturn readErr\n\t\t\t}\n\t\t\ttitles[header.ID] = header.Properties.Title\n\t\t\tif !p.mayContainReferences(data) && !bytes.Contains(data, []byte(\"NodeAttributeView\")) {\n\t\t\t\treturn nil\n\t\t\t}\n\t\t\tp.parsedDocuments++\n\t\t\ttree, readErr := dataparser.ParseJSONWithoutFix(data, luteEngine.ParseOptions)\n\t\t\tif readErr != nil || tree == nil || tree.Root == nil {\n\t\t\t\treturn fmt.Errorf(\"cannot parse document %s: %v\", absPath, readErr)\n\t\t\t}\n\t\t\trel, _ := filepath.Rel(boxDir, absPath)\n\t\t\ttree.Box, tree.Path = boxID, \"/\"+filepath.ToSlash(rel)\n\t\t\ttree.Root.Box, tree.Root.Path = tree.Box, tree.Path\n\t\t\ttree.HPath = \"/\" + tree.Root.IALAttr(\"title\")\n\t\t\tif readErr = filesys.NormalizeTreeForRead(tree); readErr != nil {\n\t\t\t\treturn readErr\n\t\t\t}\n\t\t\tif tree.Root.ID != strings.TrimSuffix(entry.Name(), \".sy\") {\n\t\t\t\treturn fmt.Errorf(\"document ID does not match path: %s\", absPath)\n\t\t\t}\n\t\t\ttitles[tree.Root.ID] = tree.Root.IALAttr(\"title\")\n\t\t\tbefore := len(p.result.References)\n\t\t\tp.tree(tree, apicontract.AssetReference{Notebook: boxID, RootID: tree.Root.ID, Path: tree.Path})\n\t\t\tretain := false\n\t\t\tif len(p.result.References) > before {\n\t\t\t\tp.files = append(p.files, &assetRelinkFile{path: absPath, before: data, tree: tree, items: p.referenceItems(before)})\n\t\t\t\tretain = true","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/asset_relink.go#L170-L206","documentation":"After preliminary content checks, the document is parsed with dataparser.ParseJSONWithoutFix. If parsing fails or yields a nil tree/root, the scan reports 'cannot parse document' wrapping the underlying error. Unlike the raw json.Valid check, this catches structurally valid JSON that is not a valid document tree.","triggerScenarios":"A .sy file with valid JSON but a malformed document structure (missing root node, wrong node kinds) that ParseJSONWithoutFix cannot build into a tree; tree or tree.Root is nil after parsing; encountered during the relink notebook scan.","commonSituations":"Documents produced or mutated by third-party scripts that wrote plausible-but-invalid JSON; forward/backward format incompatibility after a version change; corruption that preserves JSON validity but breaks the AST invariants.","solutions":["Read the wrapped %v cause to see why parsing failed and fix the document accordingly.","Restore the document from history or sync snapshots; if it is disposable, delete it.","Open and resave the document in the SiYuan app so the normal parser can repair it, then retry the relink.","If it stems from a format-version mismatch, upgrade/downgrade SiYuan to a compatible version before scanning."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err != nil && strings.HasPrefix(err.Error(), \"cannot parse document\") {\n    // inspect wrapped cause, restore or repair the document\n}","preventionTips":["Use the app to create/mutate documents rather than external scripts","Keep SiYuan versions compatible with your data format","Restore corrupt documents from snapshots promptly"],"tags":["parsing","ast","asset-relink"],"backgroundTag":"json-parse-error","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"}