{"record":{"id":"4255b57f199fe9e0","repo":"siyuan-note/siyuan","slug":"sort-target-document-s-not-found","errorCode":null,"errorMessage":"sort target document [%s] not found","messagePattern":"sort target document \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":3124,"sourceCode":"\t}\n\tinsertIndex := 0\n\tif \"after\" == position {\n\t\tinsertIndex = len(orderedIDs)\n\t}\n\tif \"\" != targetID {\n\t\tinsertIndex = -1\n\t\tfor i, currentID := range orderedIDs {\n\t\t\tif currentID == targetID {\n\t\t\t\tinsertIndex = i\n\t\t\t\tif \"after\" == position {\n\t\t\t\t\tinsertIndex++\n\t\t\t\t}\n\t\t\t\tbreak\n\t\t\t}\n\t\t}\n\t\tif 0 > insertIndex {\n\t\t\tfileTreeSortLock.Unlock()\n\t\t\treturn fmt.Errorf(\"sort target document [%s] not found\", targetID)\n\t\t}\n\t}\n\torderedIDs = append(orderedIDs, \"\")\n\tcopy(orderedIDs[insertIndex+1:], orderedIDs[insertIndex:])\n\torderedIDs[insertIndex] = id\n\tsortIDs := make(map[string]int, len(orderedIDs))\n\tfor i, orderedID := range orderedIDs {\n\t\tsortIDs[orderedID] = i + 1\n\t}\n\tmaps.Copy(fullSortIDs, sortIDs)\n\tif err = writeSortConfMap(confPath, fullSortIDs); nil != err {\n\t\tfileTreeSortLock.Unlock()\n\t\treturn err\n\t}\n\tfileTreeSortLock.Unlock()\n\tpushFiletreeSortChanged(sortIDs)\n\treturn nil\n}","sourceCodeStart":3106,"sourceCodeEnd":3142,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L3106-L3142","documentation":"When reordering sibling documents by custom order, the kernel searches the current sibling list for the targetID the dragged document should be placed relative to. If insertIndex stays negative, the target document is not among the parent's children (or the parent itself was not found) and the operation aborts while holding fileTreeSortLock.","triggerScenarios":"Calling docSort/placeDocInSiblingOrder with a targetID that is not a sibling in the resolved ordered list — e.g. the target is in another parent, was deleted, or is the document being moved itself in an inconsistent request.","commonSituations":"Two windows with stale file trees; a sync pass removed or moved the target document; client-side drag code sends an outdated target ID after another reorganization.","solutions":["Refresh the document list and retry with a targetID that currently exists under the same parent","Confirm targetID is a direct sibling (same parent path) of the moved document","If migrating code, re-read the current sort order before computing the insert position"],"exampleFix":"// before\nsortDoc(id, oldTargetID)\n// after\nconst target = (await api.post('/api/filetree/getDocInfo', {id: targetID})).data\nif (!target) targetID = await firstSiblingOf(parentID)\nsortDoc(id, targetID)","handlingStrategy":"validation","validationCode":"// ensure target is a current sibling of the moved doc\nconst info = (await api.post('/api/filetree/getDocInfo', {id: targetID})).data\nif (!info) { /* re-fetch sibling list and pick a new target */ }","typeGuard":null,"tryCatchPattern":"try { await moveDoc(id, targetID) } catch (e) { if (/sort target document .* not found/.test(e)) await reloadFileTree() }","preventionTips":["Refresh the file tree immediately before drag operations in multi-window setups","Never cache target IDs across sync operations","Validate target parentage client-side before calling the sort API"],"tags":["sorting","document-tree","stale-reference"],"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"}