{"record":{"id":"c3a426fe8802cda1","repo":"siyuan-note/siyuan","slug":"target-id-s-is-not-in-the-current-order","errorCode":null,"errorMessage":"target ID [%s] is not in the current order","messagePattern":"target ID \\[(.+?)\\] is not in the current order","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2788,"sourceCode":"\nfunc mergeRequestedSortOrder(currentIDs, requestedPaths []string) (ret []string) {\n\trequestedIDs := make([]string, 0, len(requestedPaths))\n\tfor _, requestedPath := range requestedPaths {\n\t\trequestedIDs = append(requestedIDs, util.GetTreeID(requestedPath))\n\t}\n\treturn mergeRequestedIDOrder(currentIDs, requestedIDs)\n}\n\nfunc reorderIDSequence(currentIDs, sourceIDs []string, targetID, position string) (ret []string, changed bool, err error) {\n\tif err = validateReorderArgs(sourceIDs, targetID, position); nil != err {\n\t\treturn\n\t}\n\tcurrentSet := make(map[string]struct{}, len(currentIDs))\n\tfor _, id := range currentIDs {\n\t\tcurrentSet[id] = struct{}{}\n\t}\n\tif _, exists := currentSet[targetID]; !exists {\n\t\treturn nil, false, fmt.Errorf(\"target ID [%s] is not in the current order\", targetID)\n\t}\n\tsourceSet := make(map[string]struct{}, len(sourceIDs))\n\tfor _, sourceID := range sourceIDs {\n\t\tif _, exists := currentSet[sourceID]; !exists {\n\t\t\treturn nil, false, fmt.Errorf(\"source ID [%s] is not in the current order\", sourceID)\n\t\t}\n\t\tsourceSet[sourceID] = struct{}{}\n\t}\n\tremaining := make([]string, 0, len(currentIDs)-len(sourceIDs))\n\tfor _, id := range currentIDs {\n\t\tif _, source := sourceSet[id]; !source {\n\t\t\tremaining = append(remaining, id)\n\t\t}\n\t}\n\ttargetIndex := -1\n\tfor i, id := range remaining {\n\t\tif id == targetID {\n\t\t\ttargetIndex = i","sourceCodeStart":2770,"sourceCodeEnd":2806,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/file.go#L2770-L2806","documentation":"reorderIDSequence in kernel/model/file.go validates a drag-and-drop reorder of a file-tree sort sequence. Before moving source items, it builds a set of the currently known IDs and checks that the target (drop anchor) ID is one of them. If the target ID is absent from the current order, the reorder is aborted with this error and nothing is changed.","triggerScenarios":"Calling the file-tree sort API (reorderIDSequence path, e.g. via SetFileTreeSort / drag sort) with a targetID that does not appear in currentIDs — typically a stale ID of a document or notebook that was deleted or renamed, or an ID from a different parent folder than the one being reordered.","commonSituations":"Frontend sent a drop anchor from an outdated tree snapshot (the doc was deleted by another client/device between render and drop); caller passes a notebook ID where the sequence only contains document IDs or vice versa; target doc lives under a different parent than the sources.","solutions":["Refresh the current sort sequence (re-list the parent's children) and re-read the target ID from the fresh data before retrying the reorder.","Verify the target ID exists on disk (data/<boxID>/<path>/<id>.sy) and belongs to the same parent folder as the reorder operation.","If the target was intentionally deleted, remove it from the request instead of retrying — the sequence cannot anchor to a non-existent item.","Check that the request does not confuse notebook-level and document-level sort sequences."],"exampleFix":"// before\nerr := reorder(&req) // targetID from stale UI state\n// after\nids := loadCurrentOrder(parentPath)\nif !contains(ids, req.TargetID) {\n    req.TargetID = ids[len(ids)-1] // re-anchor to a valid item from fresh data\n}\nerr := reorder(&req)","handlingStrategy":"validation","validationCode":"const current = await loadSortOrder(parentPath);\nif (!current.includes(targetID)) {\n  throw new Error(`target ${targetID} absent from current order; refresh before sorting`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await api.setFileTreeSort(payload);\n} catch (e) {\n  if (String(e).includes(\"is not in the current order\")) {\n    await refreshFileTree();\n    return retryOnceWithFreshOrder();\n  }\n  throw e;\n}","preventionTips":["Always re-fetch the current order immediately before issuing a reorder request","Never reuse target IDs cached from a previous render of the file tree","Keep notebook-level and document-level IDs in separate sort payloads"],"tags":["file-tree","sort","validation","stale-id"],"backgroundTag":"resource-not-found","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"}