{"record":{"id":"778701562598f6e3","repo":"siyuan-note/siyuan","slug":"source-document-s-is-unavailable","errorCode":null,"errorMessage":"source document [%s] is unavailable","messagePattern":"source document \\[(.+?)\\] is unavailable","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file_tree_reorder.go","lineNumber":153,"sourceCode":"\tcurrentIDs := make([]string, 0, len(docs))\n\tfor _, doc := range docs {\n\t\tbyID[doc.ID] = doc\n\t\tcurrentIDs = append(currentIDs, doc.ID)\n\t}\n\tsiblingIDs, err := loadSiblingCustomOrder(box.ID, parentDir, existingSorts)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tfor _, id := range siblingIDs {\n\t\tif byID[id] == nil {\n\t\t\treturn nil, fmt.Errorf(\"document [%s] could not be read\", id)\n\t\t}\n\t}\n\tvar fromPaths []string\n\tfor _, id := range sourceIDs {\n\t\tsource := treenode.GetBlockTree(id)\n\t\tif !isSortableDocument(source) || Conf.Box(source.BoxID) == nil {\n\t\t\treturn nil, fmt.Errorf(\"source document [%s] is unavailable\", id)\n\t\t}\n\t\tif source.BoxID == target.BoxID && (target.Path == source.Path ||\n\t\t\tstrings.HasPrefix(target.Path, strings.TrimSuffix(source.Path, \".sy\")+\"/\")) {\n\t\t\treturn nil, errors.New(Conf.Language(87))\n\t\t}\n\t\tif byID[id] != nil {\n\t\t\tcontinue\n\t\t}\n\t\tsourceParent := path.Dir(source.Path)\n\t\tif sourceParent != \"/\" {\n\t\t\tsourceParent += \".sy\"\n\t\t}\n\t\tsourceDocs, _, loadErr := ListDocTree(source.BoxID, sourceParent, util.SortModeCustom, false, true, int(^uint(0)>>1))\n\t\tif loadErr != nil {\n\t\t\treturn nil, loadErr\n\t\t}\n\t\tfor _, doc := range sourceDocs {\n\t\t\tif doc.ID == id {","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file_tree_reorder.go#L135-L171","documentation":"ReorderDocTree validates each requested source ID the same way as the target: it must resolve to a sortable root document in an opened notebook. If any source fails this check, the whole reorder is rejected atomically — no partial moves are applied.","triggerScenarios":"Calling ReorderDocTree with a sourceIDs entry that is missing from the block tree, is not a root 'd' block, or belongs to a notebook that is not opened (Conf.Box == nil).","commonSituations":"Multi-select drag where one selected document was deleted meanwhile; passing child block IDs; dragging across from a closed notebook.","solutions":["Prune sourceIDs to currently existing root document IDs before calling","Open the notebooks of all source documents","Re-fetch the selection from the current file tree to avoid stale IDs"],"exampleFix":"// before\napi.post('/api/filetree/reorderDocs', {sourceIDs: selected, targetID, position})\n// after\nconst valid = []\nfor (const id of selected) if (await isRootDoc(id)) valid.push(id)\napi.post('/api/filetree/reorderDocs', {sourceIDs: valid, targetID, position})","handlingStrategy":"validation","validationCode":"const validSources = sourceIDs.filter(id => { const bt = getBlockTree(id); return bt && bt.type === 'd' && bt.rootID === bt.id && isOpenedNotebook(bt.boxID) })","typeGuard":"const isSortableSource = (bt) => !!bt && bt.type === 'd' && bt.rootID === bt.id;","tryCatchPattern":"try { await reorderDocs(sourceIDs, targetID, pos) } catch (e) { if (/source document .* is unavailable/.test(e)) { dropInvalidSources(); await retry() } }","preventionTips":["Validate every multi-selected ID before issuing the reorder","Invalidate selections when documents are deleted via push events","Group operations per opened notebook"],"tags":["validation","document-tree","sorting","argument-validation"],"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"}