{"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":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file_tree_reorder.go","lineNumber":177,"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":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file_tree_reorder.go#L159-L195","documentation":"ReorderDocTree re-reads every source document from its parent directory listing after moving it out of any other parent context. If a source ID cannot be produced by that read (it is not a readable child where expected), the reorder is aborted, keeping current order and from-paths consistent.","triggerScenarios":"A source document passes the block-tree check but the actual directory listing cannot produce it — e.g. the .sy file was deleted between checks, the path is unreadable, or the source's parent path resolution (after detaching from a previous parent) fails.","commonSituations":"Concurrent modification: sync or another window deletes/renames the document while a reorder is in flight; external filesystem manipulation; corrupted .sy path in the block tree index.","solutions":["Retry after the concurrent operation finishes; re-open/reindex the notebook","Verify the .sy file exists at the block tree's recorded path on disk","Rebuild the block tree index (rebuild index for the notebook) if paths are stale","Re-issue the reorder with freshly fetched document IDs"],"exampleFix":"// before\nawait reorderDocs(sourceIDs, targetID, 'left')\n// after\nawait refreshNotebookIndex(boxID)\nconst fresh = sourceIDs.filter(id => await docReadable(id))\nif (fresh.length === sourceIDs.length) await reorderDocs(fresh, targetID, 'left')","handlingStrategy":"retry","validationCode":"// confirm each source resolves right before the call\nconst allReadable = sourceIDs.every(id => listDocsUnderPath(path.dirname(getBlockTree(id).path)).some(d => d.id === id))","typeGuard":null,"tryCatchPattern":"try { await reorderDocs(...) } catch (e) { if (/source document .* could not be read/.test(e)) { await waitIdle(); await reloadNotebook(boxID); await retryOnce() } }","preventionTips":["Avoid concurrent document mutations (sync, other windows) during reorders","Rebuild the index after external .sy file changes","Re-read IDs from the live tree rather than long-lived caches"],"tags":["document-tree","sorting","concurrency","stale-data"],"backgroundTag":"record-not-found","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"}