{"record":{"id":"a90a28052157a02e","repo":"siyuan-note/siyuan","slug":"get-block-failed","errorCode":null,"errorMessage":"get block failed: ","messagePattern":"get block failed: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/api/block_op.go","lineNumber":37,"sourceCode":"import (\n\t\"errors\"\n\t\"fmt\"\n\n\t\"github.com/88250/gulu\"\n\t\"github.com/88250/lute\"\n\t\"github.com/88250/lute/ast\"\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/siyuan-note/siyuan/kernel/apicontract\"\n\t\"github.com/siyuan-note/siyuan/kernel/filesys\"\n\t\"github.com/siyuan-note/siyuan/kernel/model\"\n\t\"github.com/siyuan-note/siyuan/kernel/treenode\"\n\t\"github.com/siyuan-note/siyuan/kernel/util\"\n)\n\nfunc buildUpdatedTaskListItemBlockDOM(id, marker string, luteEngine *lute.Lute) (data string, err error) {\n\tblock, err := model.GetBlock(id, nil)\n\tif err != nil {\n\t\treturn \"\", errors.New(\"get block failed: \" + err.Error())\n\t}\n\n\tif \"NodeListItem\" != block.Type {\n\t\treturn \"\", errors.New(\"block is not a list item\")\n\t}\n\n\ttree, err := filesys.LoadTree(block.Box, block.Path, luteEngine)\n\tif err != nil {\n\t\treturn \"\", errors.New(\"load tree failed: \" + err.Error())\n\t}\n\n\tli := treenode.GetNodeInTree(tree, id)\n\tif li == nil {\n\t\treturn \"\", errors.New(\"block not found\")\n\t}\n\n\tif 3 != li.ListData.Typ {\n\t\treturn \"\", errors.New(\"block is not a task list item\")","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/api/block_op.go#L19-L55","documentation":"buildUpdatedTaskListItemBlockDOM calls model.GetBlock(id, nil) to load a block by ID; on failure it wraps the underlying message in 'get block failed: ...'. The block ID could not be found or the underlying store query errored, so the task list item DOM cannot be rebuilt.","triggerScenarios":"Calling the block-op endpoint (setBlockAttrs/updateBlock-style flows for task list items) with a block ID that does not exist in the SQL index or whose tree is missing.","commonSituations":"Stale client references after the block was deleted; unindexed docs (index queue lag); typo'd or truncated block ID.","solutions":["Verify the block ID exists (sql query or /api/query/block) before calling the operation","Refresh the client's block reference from a recent DOM/SQL snapshot","Rebuild the index (重建索引) if the block exists in the .sy file but not in the index"],"exampleFix":"// before\nawait api.setBlockAttrs(deletedId, attrs)\n// after\nconst block = await api.getBlockByID(id)\nif (block) await api.setBlockAttrs(id, attrs)","handlingStrategy":"validation","validationCode":"const exists = await fetchPost('/api/query/block', {id});\nif (!exists.data) throw new Error(`block ${id} gone`);","typeGuard":null,"tryCatchPattern":"try { await setBlockAttrs(id, attrs) } catch (e) { if (String(e).includes('get block failed')) await refreshBlockRefs(id) }","preventionTips":["Refresh block references after any delete/update transaction","Handle index rebuilds by re-querying IDs","Validate IDs come from recent getDoc responses"],"tags":["blocks","api","not-found"],"backgroundTag":"record-not-found","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"}