{"record":{"id":"0c597390c3cf44bd","repo":"siyuan-note/siyuan","slug":"target-document-s-is-unavailable","errorCode":null,"errorMessage":"target document [%s] is unavailable","messagePattern":"target document \\[(.+?)\\] is unavailable","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file_tree_reorder.go","lineNumber":112,"sourceCode":"\tinherited, err := ResolveDocTreeSortMode(boxID, parentPath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif inherited == util.SortModeCustom {\n\t\treturn nil, nil\n\t}\n\treturn &mode, nil\n}\n\n// ReorderDocTree 在移动前检查完整列表，确认冲突后仅设置目标列表的排序方式。\nfunc ReorderDocTree(sourceIDs []string, targetID, position string, preview, removeSorts bool) (ret *DocTreeReorderResult, err error) {\n\tif err = validateReorderArgs(sourceIDs, targetID, position); err != nil {\n\t\treturn\n\t}\n\tFlushTxQueue()\n\ttarget := treenode.GetBlockTree(targetID)\n\tif !isSortableDocument(target) || Conf.Box(target.BoxID) == nil {\n\t\treturn nil, fmt.Errorf(\"target document [%s] is unavailable\", targetID)\n\t}\n\tbox := Conf.Box(target.BoxID)\n\tparentDir := path.Dir(target.Path)\n\tconfPath := filepath.Join(util.DataDir, box.ID, \".siyuan\", \"sort.json\")\n\texistingSorts, err := readSortConfMap(confPath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tlistPath := parentDir\n\tif listPath != \"/\" {\n\t\tlistPath += \".sy\"\n\t}\n\tmode, err := ResolveDocTreeSortMode(box.ID, listPath)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\t// 隐藏文档和超过显示上限的文档也必须参与排序。\n\tdocs, _, err := ListDocTree(box.ID, listPath, mode, false, true, int(^uint(0)>>1))","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file_tree_reorder.go#L94-L130","documentation":"ReorderDocTree validates the target document before applying a custom sibling reorder. The target must resolve in the block tree to a sortable root document ('d' type, root, not encrypted-conflicted) whose notebook is opened. Any miss yields this error, meaning the reorder cannot proceed because the anchor document is unavailable.","triggerScenarios":"Calling ReorderDocTree (via /api/filetree/reorderDocs contract) with a targetID that: does not exist in blocktree, is not a root document block, IsBoxDoc fails (e.g. it is a conflicted copy), or whose notebook is not opened (Conf.Box == nil).","commonSituations":"Passing a child block ID instead of a document root ID; targeting a document in a closed notebook; stale ID after the target was deleted by sync or another window.","solutions":["Verify targetID is a root document ID (type 'd', bt.RootID == bt.ID) before calling","Open the notebook containing the target document and retry","Re-fetch the sibling list to get a fresh, existing target ID","Ensure the target is not a conflicted document copy (IsBoxDoc)"],"exampleFix":"// before\nawait api.post('/api/filetree/reorderDocs', {sourceIDs, targetID: blockID, position: 'left'})\n// after\nconst bt = await getBlockTree(targetID)\nif (bt && bt.type === 'd' && bt.rootID === bt.id) {\n  await api.post('/api/filetree/reorderDocs', {sourceIDs, targetID, position: 'left'})\n}","handlingStrategy":"validation","validationCode":"function isValidTarget(bt) {\n  return bt && bt.type === 'd' && bt.rootID === bt.id && isOpenedNotebook(bt.boxID)\n}","typeGuard":"const isSortableDoc = (bt) => !!bt && bt.type === 'd' && bt.rootID === bt.id;","tryCatchPattern":"try { await reorderDocs(sources, targetID, pos) } catch (e) { if (/target document .* is unavailable/.test(e)) await refreshTreeAndPrompt() }","preventionTips":["Always pass root document IDs (type 'd'), never child block IDs","Check the notebook is open before referencing any document in it","Refresh block references after deletions or sync"],"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"}