siyuan-note/siyuan · error
target document [ ] is unavailable
Error message
target document [%s] is unavailable
What it means
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.
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)
Example fix
// before
await api.post('/api/filetree/reorderDocs', {sourceIDs, targetID: blockID, position: 'left'})
// after
const bt = await getBlockTree(targetID)
if (bt && bt.type === 'd' && bt.rootID === bt.id) {
await api.post('/api/filetree/reorderDocs', {sourceIDs, targetID, position: 'left'})
} Defensive patterns
Strategy: validation
Validate before calling
function isValidTarget(bt) {
return bt && bt.type === 'd' && bt.rootID === bt.id && isOpenedNotebook(bt.boxID)
} Type guard
const isSortableDoc = (bt) => !!bt && bt.type === 'd' && bt.rootID === bt.id;
Try / catch
try { await reorderDocs(sources, targetID, pos) } catch (e) { if (/target document .* is unavailable/.test(e)) await refreshTreeAndPrompt() } Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- source document [ ] is unavailable
- Conf.Language(87)
- document [ ] could not be read
- duplicate notebook ID
- invalid document file
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/0c597390c3cf44bd.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/file_tree_reorder.go:112
inherited, err := ResolveDocTreeSortMode(boxID, parentPath)
if err != nil {
return nil, err
}
if inherited == util.SortModeCustom {
return nil, nil
}
return &mode, nil
}
// ReorderDocTree 在移动前检查完整列表,确认冲突后仅设置目标列表的排序方式。
func ReorderDocTree(sourceIDs []string, targetID, position string, preview, removeSorts bool) (ret *DocTreeReorderResult, err error) {
if err = validateReorderArgs(sourceIDs, targetID, position); err != nil {
return
}
FlushTxQueue()
target := treenode.GetBlockTree(targetID)
if !isSortableDocument(target) || Conf.Box(target.BoxID) == nil {
return nil, fmt.Errorf("target document [%s] is unavailable", targetID)
}
box := Conf.Box(target.BoxID)
parentDir := path.Dir(target.Path)
confPath := filepath.Join(util.DataDir, box.ID, ".siyuan", "sort.json")
existingSorts, err := readSortConfMap(confPath)
if err != nil {
return nil, err
}
listPath := parentDir
if listPath != "/" {
listPath += ".sy"
}
mode, err := ResolveDocTreeSortMode(box.ID, listPath)
if err != nil {
return nil, err
}
// 隐藏文档和超过显示上限的文档也必须参与排序。
docs, _, err := ListDocTree(box.ID, listPath, mode, false, true, int(^uint(0)>>1))View on GitHub (pinned to 9f775e8a12)