{"record":{"id":"7d70e1dc8ad36a0c","repo":"siyuan-note/siyuan","slug":"document-id-does-not-match-path-s","errorCode":null,"errorMessage":"document ID does not match path: %s","messagePattern":"document ID does not match path: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/asset_relink.go","lineNumber":198,"sourceCode":"\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\n\t\t\t}\n\t\t\tast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {\n\t\t\t\tif entering && n.Type == ast.NodeAttributeView {\n\t\t\t\t\tretain = true\n\t\t\t\t}\n\t\t\t\treturn ast.WalkContinue\n\t\t\t})\n\t\t\tif retain {\n\t\t\t\tp.trees = append(p.trees, tree)\n\t\t\t}","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/asset_relink.go#L180-L216","documentation":"SiYuan requires that a document file's name equals the root block ID (filename is '<ID>.sy'). After parsing, if tree.Root.ID differs from the filename stem, the scan aborts because references would be attributed to the wrong block ID and downstream relinking/history would corrupt the index.","triggerScenarios":"A .sy file was renamed on disk (manually or by a script) without updating the root ID inside the JSON, or the document was copied to a new filename while retaining the original ID; detected as tree.Root.ID != strings.TrimSuffix(entry.Name(), \".sy\").","commonSituations":"Users renaming .sy files in a file manager to reorganize; duplicate-document scripts copying files without regenerating IDs; restoring backups under different filenames; git operations that renamed files.","solutions":["Rename the file back to '<RootID>.sy' matching the root ID in its JSON content.","Or use the SiYuan app's duplicate/export features, which regenerate IDs, instead of copying files manually.","If the document is a stray duplicate, delete it.","After fixing, rerun the relink with dryRun=true to confirm the whole notebook scans cleanly."],"exampleFix":"// before (shell)\nmv data/notebooks/xxx/20240101120000-abc.sy data/notebooks/xxx/my-note.sy\n// after (shell)\nmv data/notebooks/xxx/my-note.sy data/notebooks/xxx/20240101120000-abc.sy","handlingStrategy":"validation","validationCode":"var hdr struct{ ID string `json:\"ID\"` }\njson.Unmarshal(data, &hdr)\nif hdr.ID != strings.TrimSuffix(filepath.Base(syPath), \".sy\") {\n    return fmt.Errorf(\"ID/filename mismatch: %s\", syPath)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never rename .sy files in a file manager","Duplicate documents via the app so IDs regenerate","Check filename == RootID after any manual restore"],"tags":["document-id","naming","asset-relink"],"backgroundTag":"invalid-identifier-format","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"}