siyuan-note/siyuan · error
sort target document
Error message
sort target document [%s] is not a sibling of the new document
What it means
When a sortTargetID is given, the target document must be a valid, sortable document tree node that lives in the same notebook (same BoxID) and in the same parent directory as the new document's path. Otherwise the positional placement is impossible and this sibling-mismatch error is returned.
Solutions
- Ensure sortTargetID is the ID of a document in the same notebook and same parent folder as the new document
- Clear the stale target and re-resolve it from the current tree before creating the doc
- Verify the target is a document node (has a tree entry), not a regular block
- Drop the sortTargetID/sortPosition pair to fall back to default placement
Example fix
// before: target in another notebook
{notebook: "box-1", path: "/a/b", sortTargetID: docInBox2ID, sortPosition: "after"}
// after: target is a sibling
{notebook: "box-1", path: "/a/b", sortTargetID: siblingDocInBox1ID, sortPosition: "after"} Defensive patterns
Strategy: validation
Validate before calling
async function canSortAgainst(sortTargetID, boxID, newPath) {
const target = await fetchPost("/api/block/getBlockInfo", {id: sortTargetID});
if (!target || target.root_id !== sortTargetID) return false; // must be a document
if (target.box !== boxID) return false; // same notebook
return pathDirname(target.path) === pathDirname(newPath); // same parent folder
} Type guard
function isSiblingDocument(target, boxID, newPath) {
return !!target && target.type === "document" &&
target.box === boxID &&
dirname(target.path) === dirname(newPath);
} Try / catch
try {
await createDocWithMd(args);
} catch (e) {
if (/not a sibling of the new document/.test(e.message)) {
delete args.sortTargetID; delete args.sortPosition;
return createDocWithMd(args); // fall back to default placement
}
throw e;
} Prevention
- Resolve sortTargetID from the same folder view where the doc is created
- Re-resolve the target after moving/deleting documents; never reuse stale IDs
- Verify the target is a document node, not an arbitrary block
When it happens
Trigger: CreateDocByMd with sortTargetID pointing to a document that does not exist in the block tree (nil target), is not sortable, is in a different notebook, or is in another folder than the parent path p of the new document.
Common situations: Plugins positioning a new doc relative to a doc chosen from search results in a different notebook/folder; stale sortTargetID after the target was moved or deleted; passing a block ID (non-document) as sortTargetID.
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
- invalid sort position
- AI editor action must not be empty
- block [ ] type is locked: expected , got
- block swap requires two non-document blocks
- Bookmark cannot be empty
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/04a7c7eea7d7689b.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/model/file.go:1305
}
func createDocByMd(boxID, p, title, md string, sorts []string, arg map[string]any, syncWrite bool) (tree *parse.Tree, err error) {
createDocLock.Lock()
defer createDocLock.Unlock()
box, err := getOpenedBox(boxID)
if nil != err {
return
}
sortTargetID, _ := arg["sortTargetID"].(string)
sortPosition, _ := arg["sortPosition"].(string)
if "" != sortTargetID {
if "before" != sortPosition && "after" != sortPosition {
return nil, fmt.Errorf("invalid sort position [%s]", sortPosition)
}
target := treenode.GetBlockTree(sortTargetID)
if !isSortableDocument(target) || target.BoxID != boxID || path.Dir(target.Path) != path.Dir(p) {
return nil, fmt.Errorf("sort target document [%s] is not a sibling of the new document", sortTargetID)
}
} else if "" != sortPosition {
return nil, errors.New("sort target ID is required when sort position is specified")
}
luteEngine := util.NewLute()
luteEngine.SetHTMLTag2TextMark(true)
dom := luteEngine.Md2BlockDOM(md, false)
tree, err = createDoc0(box.ID, p, title, dom, false, syncWrite)
if err != nil {
return
}
FlushTxQueue()
if "" != sortTargetID {
if _, sortErr := ReorderDocs([]string{tree.ID}, sortTargetID, sortPosition); nil != sortErr {
logging.LogErrorf("reorder created document [%s] failed: %s", tree.ID, sortErr)
box.setSortByConf(path.Dir(tree.Path), tree.ID)View on GitHub (pinned to 9f775e8a12)