{"record":{"id":"04a7c7eea7d7689b","repo":"siyuan-note/siyuan","slug":"sort-target-document-s-is-not-a-sibling-of-the","errorCode":null,"errorMessage":"sort target document [%s] is not a sibling of the new document","messagePattern":"sort target document \\[(.+?)\\] is not a sibling of the new document","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/file.go","lineNumber":1305,"sourceCode":"}\n\nfunc createDocByMd(boxID, p, title, md string, sorts []string, arg map[string]any, syncWrite bool) (tree *parse.Tree, err error) {\n\tcreateDocLock.Lock()\n\tdefer createDocLock.Unlock()\n\n\tbox, err := getOpenedBox(boxID)\n\tif nil != err {\n\t\treturn\n\t}\n\tsortTargetID, _ := arg[\"sortTargetID\"].(string)\n\tsortPosition, _ := arg[\"sortPosition\"].(string)\n\tif \"\" != sortTargetID {\n\t\tif \"before\" != sortPosition && \"after\" != sortPosition {\n\t\t\treturn nil, fmt.Errorf(\"invalid sort position [%s]\", sortPosition)\n\t\t}\n\t\ttarget := treenode.GetBlockTree(sortTargetID)\n\t\tif !isSortableDocument(target) || target.BoxID != boxID || path.Dir(target.Path) != path.Dir(p) {\n\t\t\treturn nil, fmt.Errorf(\"sort target document [%s] is not a sibling of the new document\", sortTargetID)\n\t\t}\n\t} else if \"\" != sortPosition {\n\t\treturn nil, errors.New(\"sort target ID is required when sort position is specified\")\n\t}\n\n\tluteEngine := util.NewLute()\n\tluteEngine.SetHTMLTag2TextMark(true)\n\tdom := luteEngine.Md2BlockDOM(md, false)\n\ttree, err = createDoc0(box.ID, p, title, dom, false, syncWrite)\n\tif err != nil {\n\t\treturn\n\t}\n\n\tFlushTxQueue()\n\tif \"\" != sortTargetID {\n\t\tif _, sortErr := ReorderDocs([]string{tree.ID}, sortTargetID, sortPosition); nil != sortErr {\n\t\t\tlogging.LogErrorf(\"reorder created document [%s] failed: %s\", tree.ID, sortErr)\n\t\t\tbox.setSortByConf(path.Dir(tree.Path), tree.ID)","sourceCodeStart":1287,"sourceCodeEnd":1323,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/file.go#L1287-L1323","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: target in another notebook\n{notebook: \"box-1\", path: \"/a/b\", sortTargetID: docInBox2ID, sortPosition: \"after\"}\n// after: target is a sibling\n{notebook: \"box-1\", path: \"/a/b\", sortTargetID: siblingDocInBox1ID, sortPosition: \"after\"}","handlingStrategy":"validation","validationCode":"async function canSortAgainst(sortTargetID, boxID, newPath) {\n  const target = await fetchPost(\"/api/block/getBlockInfo\", {id: sortTargetID});\n  if (!target || target.root_id !== sortTargetID) return false;      // must be a document\n  if (target.box !== boxID) return false;                            // same notebook\n  return pathDirname(target.path) === pathDirname(newPath);          // same parent folder\n}","typeGuard":"function isSiblingDocument(target, boxID, newPath) {\n  return !!target && target.type === \"document\" &&\n    target.box === boxID &&\n    dirname(target.path) === dirname(newPath);\n}","tryCatchPattern":"try {\n  await createDocWithMd(args);\n} catch (e) {\n  if (/not a sibling of the new document/.test(e.message)) {\n    delete args.sortTargetID; delete args.sortPosition;\n    return createDocWithMd(args); // fall back to default placement\n  }\n  throw e;\n}","preventionTips":["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"],"tags":["api","validation","document-creation","sort"],"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"}