{"record":{"id":"9ce35f119265810e","repo":"siyuan-note/siyuan","slug":"source-ids-must-not-be-empty","errorCode":null,"errorMessage":"source IDs must not be empty","messagePattern":"source IDs must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":2743,"sourceCode":"\t}\n\tmaps.Copy(fullSortIDs, sortIDs)\n\tif writeErr := writeSortConfMap(confPath, fullSortIDs); nil != writeErr {\n\t\tfileTreeSortLock.Unlock()\n\t\treturn ret, writeErr\n\t}\n\tfileTreeSortLock.Unlock()\n\n\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 {","sourceCodeStart":2725,"sourceCodeEnd":2761,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L2725-L2761","documentation":"validateReorderArgs enforces that a document reorder request carries at least one source document ID. An empty sourceIDs slice makes the operation meaningless and is rejected up front with this plain error. It runs before any tree lookups, so no documents are touched.","triggerScenarios":"Calling the reorder API with sourceIDs: [] or null; frontend code invoking reorder after a selection was programmatically cleared.","commonSituations":"Drag-and-drop handlers firing with an empty selection; batch scripts looping until the source list is exhausted then issuing one final empty call; filters that removed all IDs before sending.","solutions":["Guard the call site: skip the API call when the source list length is 0","Ensure the UI selection is non-empty before enabling the reorder action","Fix any pre-send filtering that can drain the array entirely","Handle the empty case as a no-op rather than an error in your wrapper"],"exampleFix":"// before\nreorderDocs(selectedIDs, targetID, pos) // may be empty\n// after\nif (selectedIDs.length > 0) {\n    reorderDocs(selectedIDs, targetID, pos)\n}","handlingStrategy":"validation","validationCode":"if (!Array.isArray(sourceIDs) || sourceIDs.length === 0) return // no-op, skip API call","typeGuard":null,"tryCatchPattern":"try { await api.reorderDocs(src, targetID, pos) } catch (e) { if (String(e).includes(\"source IDs must not be empty\")) return /* treat as no-op */; throw e }","preventionTips":["Guard call sites: only invoke reorder with a non-empty source array","Disable reorder UI actions when the selection is empty","Return early from batch loops when the remaining list is empty"],"tags":["go","kernel","validation","empty"],"backgroundTag":"missing-required-argument","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"}