{"record":{"id":"58731dbd75a0c0b0","repo":"siyuan-note/siyuan","slug":"target-id-s-must-not-be-included-in-source-ids","errorCode":null,"errorMessage":"target ID [%s] must not be included in source IDs","messagePattern":"target ID \\[(.+?)\\] must not be included in source IDs","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2751,"sourceCode":"\tret.Changed = true\n\tret.Notebook = box.ID\n\tret.ParentPath = parentPath\n\tIncSync()\n\tpushFiletreeSortChanged(sortIDs)\n\treturn\n}\n\nfunc validateReorderArgs(sourceIDs []string, targetID, position string) error {\n\tif 1 > len(sourceIDs) {\n\t\treturn errors.New(\"source IDs must not be empty\")\n\t}\n\tif \"before\" != position && \"after\" != position {\n\t\treturn fmt.Errorf(\"invalid reorder position [%s]\", position)\n\t}\n\tseen := map[string]struct{}{}\n\tfor _, sourceID := range sourceIDs {\n\t\tif sourceID == targetID {\n\t\t\treturn fmt.Errorf(\"target ID [%s] must not be included in source IDs\", targetID)\n\t\t}\n\t\tif _, ok := seen[sourceID]; ok {\n\t\t\treturn fmt.Errorf(\"duplicate source ID [%s]\", sourceID)\n\t\t}\n\t\tseen[sourceID] = struct{}{}\n\t}\n\treturn nil\n}\n\nfunc isSortableDocument(tree *treenode.BlockTree) bool {\n\treturn nil != tree && tree.ID == tree.RootID && \"d\" == tree.Type && !IsBoxDoc(tree.BoxID, tree.RootID)\n}\n\nfunc loadSiblingCustomOrder(boxID, parentPath string, fullSortIDs map[string]int) (ret []string, err error) {\n\tabsParentPath := filepath.Join(util.DataDir, boxID, parentPath)\n\tfiles, err := os.ReadDir(absParentPath)\n\tif nil != err {\n\t\treturn nil, fmt.Errorf(\"read dir [%s] failed: %w\", absParentPath, err)","sourceCodeStart":2733,"sourceCodeEnd":2769,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L2733-L2769","documentation":"A reorder's target document is the reference point, so it cannot itself be one of the moved sources. validateReorderArgs scans sourceIDs and rejects the request if any ID equals targetID. This prevents self-referential ordering that has no defined result.","triggerScenarios":"Including the drop-target document in the dragged selection; batch scripts appending the anchor ID to the source list; UI code where the drop indicator landed on a selected document.","commonSituations":"Multi-select drag where the user starts the drag on an already-selected item that is also the drop target; automation building source lists from a range that includes the anchor.","solutions":["Exclude targetID from sourceIDs before calling the reorder API","Fix the drag-and-drop selection logic so the drop anchor is removed from the moved set","Deduplicate against the target when assembling the request programmatically"],"exampleFix":"// before\nreorderDocs(selectedIDs, targetID, \"after\")\n// after\nconst sources = selectedIDs.filter(id => id !== targetID)\nreorderDocs(sources, targetID, \"after\")","handlingStrategy":"validation","validationCode":"const sources = [...new Set(sourceIDs.filter(id => id !== targetID))]\nif (sources.length !== sourceIDs.length) { /* anchor was in the moved set; use filtered list */ }","typeGuard":null,"tryCatchPattern":"try { await api.reorderDocs(src, targetID, pos) } catch (e) { if (String(e).includes(\"must not be included in source IDs\")) { src = src.filter(id => id !== targetID); return retryOnce() } throw e }","preventionTips":["Always remove the drop anchor from the selection before building the request","In multi-select drag, detect if the drag origin is the drop target and treat it as a no-op","Filter against targetID as the last step before sending"],"tags":["go","kernel","validation","argument"],"backgroundTag":"invalid-argument-value","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"}