{"record":{"id":"178e062c06c5c1dc","repo":"siyuan-note/siyuan","slug":"get-block-tree-by-id-s-failed-after-create","errorCode":null,"errorMessage":"get block tree by id [%s] failed after create","messagePattern":"get block tree by id \\[(.+?)\\] failed after create","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/shortcuts.go","lineNumber":317,"sourceCode":"\tretID, err = createDocsByHPathSync(box.ID, hPath, dom, \"\", docID, false)\n\tif nil != err {\n\t\treturn\n\t}\n\n\tbt := treenode.GetBlockTree(retID)\n\tif err = verifyShorthandDocPersisted(bt, retID); nil != err {\n\t\treturn\n\t}\n\tbox.setSortByConf(path.Dir(bt.Path), retID)\n\n\tFlushTxQueue()\n\tPushCreate(box, bt.Path, nil)\n\treturn\n}\n\nfunc verifyShorthandDocPersisted(bt *treenode.BlockTree, expectedID string) (err error) {\n\tif nil == bt {\n\t\treturn fmt.Errorf(\"get block tree by id [%s] failed after create\", expectedID)\n\t}\n\t// 清除写入缓存，确保从文件系统重新读取并验证文档。\n\tcache.RemoveTreeDataInBox(expectedID, bt.BoxID)\n\tpersisted, err := loadTreeByBlockTree(bt)\n\tif nil != err {\n\t\treturn fmt.Errorf(\"load created shorthand document [%s] failed: %w\", expectedID, err)\n\t}\n\tif nil == persisted || persisted.ID != expectedID {\n\t\treturn fmt.Errorf(\"verify created shorthand document [%s] failed\", expectedID)\n\t}\n\treturn nil\n}\n\nvar consumeShorthandsLock = sync.Mutex{}\nvar shorthandSaveBoxUnavailableNotified bool\n\nfunc isShorthandSaveBoxAvailable(box *Box) bool {\n\treturn nil != box && !box.Closed && !box.Encrypted && !IsUserGuide(box.ID)","sourceCodeStart":299,"sourceCodeEnd":335,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/shortcuts.go#L299-L335","documentation":"verifyShorthandDocPersisted double-checks that a newly created shorthand document actually exists in the block tree and on disk. When the block tree lookup returned nil — the created document's ID is not registered — it returns \"get block tree by id [%s] failed after create\". This guards against a create that reported success but did not persist the tree record.","triggerScenarios":"createShorthandDocByDOM created the doc, then verifyShorthandDocPersisted receives a nil *treenode.BlockTree — e.g. the write failed silently, the block tree index was not updated, or a concurrent flush removed the record.","commonSituations":"Disk/index contention right after creation; asynchronous indexing not yet committed when verification runs; corrupted blocktree.db failing to return the new record; tests hitting timing windows.","solutions":["Retry the shorthand creation — the failure is usually transient index timing","Check blocktree.db integrity and rebuild the index if records are missing (rebuild index in Settings)","Verify the notebook's .sy files on disk to see whether the doc file was written; if yes, re-index; if no, inspect create logs for the underlying failure"],"exampleFix":"null","handlingStrategy":"retry","validationCode":null,"typeGuard":"// nil-check the block tree record before verification\nif bt == nil { return fmt.Errorf(\"get block tree by id [%s] failed after create\", expectedID) }","tryCatchPattern":"if err := verifyShorthandDocPersisted(bt, expectedID); err != nil {\n    time.Sleep(500 * time.Millisecond)\n    bt = treenode.GetBlockTree(expectedID) // re-fetch; index may have settled\n    err = verifyShorthandDocPersisted(bt, expectedID)\n}","preventionTips":["Ensure create operations fully flush the block tree before verification","Rebuild the index if blocktree.db lookups return nil for existing docs","Log and surface create-side failures instead of assuming success"],"tags":["shorthands","block-tree","persistence","index"],"backgroundTag":"record-not-found","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}