{"record":{"id":"dc43f913058ecb0a","repo":"siyuan-note/siyuan","slug":"errblocknotfound","errorCode":"ErrBlockNotFound","errorMessage":"block not found","messagePattern":"block not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/tree.go","lineNumber":212,"sourceCode":"\t\t\treturn\n\t\t}\n\t}\n\n\tif err = treenode.CheckSpecJSON(data); nil != err {\n\t\treturn\n\t}\n\tret, err = dataparser.ParseJSONWithoutFix(data, luteEngine.ParseOptions)\n\tif err != nil {\n\t\tlogging.LogErrorf(\"parse json to tree [%s] failed: %s\", localPath, err)\n\t\treturn\n\t}\n\treturn\n}\n\nvar (\n\tErrBoxNotFound   = errors.New(\"notebook not found\")\n\tErrBoxClosed     = errors.New(\"notebook closed\")\n\tErrBlockNotFound = errors.New(\"block not found\")\n\tErrTreeNotFound  = errors.New(\"tree not found\")\n\tErrIndexing      = errors.New(\"indexing\")\n\tErrBoxUnindexed  = errors.New(\"notebook unindexed\")\n\tErrInvalidID     = errors.New(\"invalid id\")\n)\n\nfunc LoadTreeByBlockIDWithReindex(id string) (ret *parse.Tree, err error) {\n\treturn LoadTreeByBlockIDWithReindexInBox(id, \"\")\n}\n\n// LoadTreeByBlockIDWithReindexInBox 与 LoadTreeByBlockIDWithReindex 一致，但按 boxID 路由 blocktree 查询。\nfunc LoadTreeByBlockIDWithReindexInBox(id, boxID string) (ret *parse.Tree, err error) {\n\tif \"\" == id {\n\t\tlogging.LogWarnf(\"block id is empty\")\n\t\treturn nil, ErrTreeNotFound\n\t}\n\n\tbt := treenode.GetBlockTreeInBox(id, boxID)","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/tree.go#L194-L230","documentation":"ErrBlockNotFound is the sentinel error meaning no block with the given ID exists (in the tree or index). Model functions like getRefText, getDoc, getHPathByPath and attribute-view item creation return it; API handlers also use its text directly as a generic 'block not found' response when publish access checks fail.","triggerScenarios":"Requesting doc info, ref text, or hpath by a block ID that was deleted or never existed; CreateAttributeViewItemDocs with a blockID whose block is gone; publish-access check failing for a block, where the API deliberately returns ErrBlockNotFound.Error() to avoid leaking existence.","commonSituations":"Stale client cache holding IDs of deleted blocks; pasted links to blocks removed by a sync conflict; plugin querying a block ID from an outdated bookmark; privacy protection returning 'not found' for blocks the requester may not read.","solutions":["Verify the block ID exists via /api/filetree/getDocInfo or a SQL query on blocks; refresh the client's references if the block was deleted","Re-run index rebuild (Rebuild Index) if the block exists in the .sy file but the index is stale","Re-create the deleted block or fix the referencing link/database row to point to an existing ID","Treat the error in callers with errors.Is(err, model.ErrBlockNotFound) and show a user-facing 'block does not exist' message"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"stmt := database.Query(\"SELECT id FROM blocks WHERE id = ?\", blockID)\nif len(stmt) == 0 { return fmt.Errorf(\"block %s does not exist\", blockID) }","typeGuard":null,"tryCatchPattern":"if errors.Is(err, model.ErrBlockNotFound) {\n    // show 'block does not exist', refresh references\n    return\n}","preventionTips":["Verify block IDs exist before linking or adding database rows","Refresh caches after sync to drop deleted block IDs","Never assume a pasted/bookmarked block ID is still valid"],"tags":["go","block","not-found"],"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"}