{"record":{"id":"e455b8e1cbfb90cd","repo":"siyuan-note/siyuan","slug":"source-document-s-could-not-be-read","errorCode":null,"errorMessage":"source document [%s] could not be read","messagePattern":"source document \\[(.+?)\\] could not be read","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file_tree_reorder.go","lineNumber":176,"sourceCode":"\t\tif byID[id] != nil {\n\t\t\tcontinue\n\t\t}\n\t\tsourceParent := path.Dir(source.Path)\n\t\tif sourceParent != \"/\" {\n\t\t\tsourceParent += \".sy\"\n\t\t}\n\t\tsourceDocs, _, loadErr := ListDocTree(source.BoxID, sourceParent, util.SortModeCustom, false, true, int(^uint(0)>>1))\n\t\tif loadErr != nil {\n\t\t\treturn nil, loadErr\n\t\t}\n\t\tfor _, doc := range sourceDocs {\n\t\t\tif doc.ID == id {\n\t\t\t\tbyID[id] = doc\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif byID[id] == nil {\n\t\t\treturn nil, fmt.Errorf(\"source document [%s] could not be read\", id)\n\t\t}\n\t\tcurrentIDs = append(currentIDs, id)\n\t\tfromPaths = append(fromPaths, source.Path)\n\t}\n\torderedIDs, changed, err := reorderIDSequence(currentIDs, sourceIDs, targetID, position)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tret = &DocTreeReorderResult{Changed: changed || len(fromPaths) > 0, Notebook: box.ID, ParentPath: listPath}\n\tfor i := 1; i < len(orderedIDs); i++ {\n\t\tif fileTreeSortLess(byID[orderedIDs[i]], byID[orderedIDs[i-1]], mode) {\n\t\t\tret.Conflict = true\n\t\t\tbreak\n\t\t}\n\t}\n\tif preview || !ret.Changed || ret.Conflict && !removeSorts {\n\t\treturn ret, nil\n\t}","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/file_tree_reorder.go#L158-L194","documentation":"After loading the sibling list of the source document's parent folder, ReorderDocTree could not find the requested source document ID among its siblings. This means the block-tree entry exists but the actual document file/listing is missing or unreadable, so a custom sort order involving it cannot be applied.","triggerScenarios":"Calling ReorderDocTree with a source ID whose parent's ListDocTree listing does not contain that ID — e.g. the .sy file was deleted, moved, or is excluded from the listing after the block-tree row was read.","commonSituations":"A race between index and filesystem (document removed while reorder is in flight); corrupted or out-of-sync blocktree.db; notebooks copied manually so index entries point at nonexistent files; scripts holding stale IDs.","solutions":["Verify the source document file exists on disk under the notebook's data folder and re-run the operation.","Rebuild the index (Settings - Rebuild Index / full-text rebuild) so block-tree entries match actual files.","Re-fetch the document list and use current IDs before reordering.","If a sibling listed in the saved custom order is unreadable, clean up stale entries in the sibling order (loadSiblingCustomOrder path reports the same class of problem)."],"exampleFix":"// before\nawait reorderDocTree(boxID, [staleDocID], targetID, position)\n// after\nconst docs = await listDocs(boxID, parentPath)\nconst validIDs = sourceIDs.filter(id => docs.some(d => d.id === id))\nif (validIDs.length === sourceIDs.length) {\n  await reorderDocTree(boxID, sourceIDs, targetID, position)\n}","handlingStrategy":"validation","validationCode":"const docs = await listDocs(boxID, parentPath)\nconst allPresent = sourceIDs.every(id => docs.some(d => d.id === id))\nif (!allPresent) { /* refresh IDs or abort */ }","typeGuard":null,"tryCatchPattern":"try {\n  await reorderDocTree(boxID, sourceIDs, targetID, position)\n} catch (e) {\n  if (String(e.msg).includes('could not be read')) { await refreshDocList(); retry() }\n  else throw e\n}","preventionTips":["Fetch current document IDs immediately before reordering","Rebuild the index if block-tree and files may be out of sync","Avoid reordering while sync/other sessions may delete documents concurrently"],"tags":["document-tree","file-read-failed","index-out-of-sync","reorder"],"backgroundTag":"file-read-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}