siyuan-note/siyuan · error
sort target document
Error message
sort target document [%s] not found
What it means
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.
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
Example fix
// before
sortDoc(id, oldTargetID)
// after
const target = (await api.post('/api/filetree/getDocInfo', {id: targetID})).data
if (!target) targetID = await firstSiblingOf(parentID)
sortDoc(id, targetID) Defensive patterns
Strategy: validation
Validate before calling
// ensure target is a current sibling of the moved doc
const info = (await api.post('/api/filetree/getDocInfo', {id: targetID})).data
if (!info) { /* re-fetch sibling list and pick a new target */ } Try / catch
try { await moveDoc(id, targetID) } catch (e) { if (/sort target document .* not found/.test(e)) await reloadFileTree() } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- notebook [ ] not found for document [ ]
- document [ ] could not be read
- source document [ ] could not be read
- source document [ ] is unavailable
- target document [ ] is unavailable
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/4255b57f199fe9e0.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/file.go:3124
}
insertIndex := 0
if "after" == position {
insertIndex = len(orderedIDs)
}
if "" != targetID {
insertIndex = -1
for i, currentID := range orderedIDs {
if currentID == targetID {
insertIndex = i
if "after" == position {
insertIndex++
}
break
}
}
if 0 > insertIndex {
fileTreeSortLock.Unlock()
return fmt.Errorf("sort target document [%s] not found", targetID)
}
}
orderedIDs = append(orderedIDs, "")
copy(orderedIDs[insertIndex+1:], orderedIDs[insertIndex:])
orderedIDs[insertIndex] = id
sortIDs := make(map[string]int, len(orderedIDs))
for i, orderedID := range orderedIDs {
sortIDs[orderedID] = i + 1
}
maps.Copy(fullSortIDs, sortIDs)
if err = writeSortConfMap(confPath, fullSortIDs); nil != err {
fileTreeSortLock.Unlock()
return err
}
fileTreeSortLock.Unlock()
pushFiletreeSortChanged(sortIDs)
return nil
}View on GitHub (pinned to 9f775e8a12)