{"record":{"id":"39e10de329cdb2d6","repo":"siyuan-note/siyuan","slug":"target-document-s-not-found","errorCode":null,"errorMessage":"target document [%s] not found","messagePattern":"target document \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2688,"sourceCode":"\n// ReorderResult 描述相对排序操作的结果。\ntype ReorderResult struct {\n\tChanged    bool   `json:\"changed\"`\n\tNotebook   string `json:\"notebook,omitempty\"`\n\tParentPath string `json:\"parentPath,omitempty\"`\n}\n\n// ReorderDocs 将同级文档移动到目标文档之前或之后。\nfunc ReorderDocs(sourceIDs []string, targetID, position string) (ret *ReorderResult, err error) {\n\tret = &ReorderResult{}\n\tif err = validateReorderArgs(sourceIDs, targetID, position); nil != err {\n\t\treturn\n\t}\n\n\tFlushTxQueue()\n\ttarget := treenode.GetBlockTree(targetID)\n\tif !isSortableDocument(target) {\n\t\treturn ret, fmt.Errorf(\"target document [%s] not found\", targetID)\n\t}\n\tbox := Conf.Box(target.BoxID)\n\tif nil == box {\n\t\treturn ret, fmt.Errorf(\"target document [%s] is not in an opened and unlocked notebook\", targetID)\n\t}\n\tparentPath := path.Dir(target.Path)\n\tfor _, sourceID := range sourceIDs {\n\t\tsource := treenode.GetBlockTree(sourceID)\n\t\tif !isSortableDocument(source) {\n\t\t\treturn ret, fmt.Errorf(\"source document [%s] not found\", sourceID)\n\t\t}\n\t\tif source.BoxID != target.BoxID || path.Dir(source.Path) != parentPath {\n\t\t\treturn ret, fmt.Errorf(\"source document [%s] is not a sibling of target document [%s]\", sourceID, targetID)\n\t\t}\n\t}\n\n\tfileTreeSortLock.Lock()\n\tconfPath := filepath.Join(util.DataDir, box.ID, \".siyuan\", \"sort.json\")","sourceCodeStart":2670,"sourceCodeEnd":2706,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L2670-L2706","documentation":"During document sort/reorder operations, the kernel resolves the target document via treenode.GetBlockTree and requires it to be a sortable document (an existing document block). If the target ID does not resolve to a valid document, the operation reports 'target document not found'. Note this message is also reused when the target exists but is not a sortable document, so it covers both missing and ineligible targets.","triggerScenarios":"Calling the doc sort/reorder API with a targetID of a non-existent document, a deleted document, or a non-document block; race where the document was deleted between UI listing and the reorder call.","commonSituations":"Stale UI state after another client deleted the document via sync; plugins caching document IDs across notebook rebuilds; typos or truncated IDs in manual API scripts.","solutions":["Re-fetch the document tree/notebook listing and confirm the targetID exists as a document","Refresh the frontend view so the reorder operation uses current IDs, then retry","Check the ID is a document (root block) ID, not a child block ID","If the notebook was recently synced, wait for indexing to complete before reordering"],"exampleFix":"// before\nreorderDocs(srcIDs, possiblyDeletedID, \"after\")\n// after\nif docExists(possiblyDeletedID) {\n    reorderDocs(srcIDs, possiblyDeletedID, \"after\")\n}","handlingStrategy":"validation","validationCode":"const target = await getDocTreeItem(targetID)\nif (!target || target.type !== \"document\") throw new Error(\"target document missing, refresh tree\")","typeGuard":"const isDoc = (item) => !!item && item.type === \"document\"","tryCatchPattern":"try { await api.reorderDocs(src, targetID, pos) } catch (e) { if (String(e).includes(\"target document\") && String(e).includes(\"not found\")) { await refreshFileTree(); return retryOnce() } throw e }","preventionTips":["Refresh the file tree after sync/delete events before issuing reorders","Never persist document IDs across long-lived jobs without revalidation","Distinguish document IDs from child block IDs at extraction time"],"tags":["go","kernel","document","not-found"],"backgroundTag":"entity-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"}