{"record":{"id":"4562081f91cefdb5","repo":"siyuan-note/siyuan","slug":"errtreenotfound","errorCode":"ErrTreeNotFound","errorMessage":"tree not found","messagePattern":"tree not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/tree.go","lineNumber":213,"sourceCode":"\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)\n\tif nil == bt && \"\" == boxID {","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/tree.go#L195-L231","documentation":"ErrTreeNotFound is the sentinel returned when the document tree (.sy) for a block/doc ID cannot be loaded — the document file is missing from the notebook. API handlers special-case it to show localized 'doc not found' messages (Conf.Language(15)) instead of dumping the raw error.","triggerScenarios":"getDoc/getBlockInfo paths (kernel/api/block.go:762) load a tree by block or doc ID and the .sy file does not exist; contract getters (getHPathByIDContract, getPathByIDContract, getFullHPathByIDContract) and export preflight (prepareExportAssets) propagate it; LoadTreeByBlockIDWithReindex fails to find the doc.","commonSituations":"Doc deleted on another device and sync removed the .sy while an old link/ID is still requested; stale browser tab holding a removed doc ID; corrupted or manually deleted data/ folder contents; export of a doc that no longer exists.","solutions":["Confirm the doc ID exists (query blocks table or list files under data/<box>/) and fix stale references","Sync the workspace so missing docs are restored or removed references converge","Map errors.Is(err, model.ErrTreeNotFound) to the localized message (Conf.Language(15)) in handlers rather than generic error text","Reindex the notebook if data files exist but the index is stale (though typically the file is genuinely gone)"],"exampleFix":"// before\nret.Msg = err.Error()\n\n// after\ncase errors.Is(err, model.ErrTreeNotFound):\n    ret.Msg = fmt.Sprintf(model.Conf.Language(15), id)\ndefault:\n    ret.Msg = err.Error()","handlingStrategy":"fallback","validationCode":"// TypeScript: check the doc path resolves before loading by ID\nconst p = await fetchPost('/api/filetree/getHPathByID', { id });\nif (p.code !== 0) throw new Error('doc missing: ' + id);","typeGuard":"function isTreeNotFound(msg: string | null | undefined): boolean {\n  return msg === 'tree not found';\n}","tryCatchPattern":"// Go\ncase errors.Is(err, model.ErrTreeNotFound):\n    ret.Msg = fmt.Sprintf(model.Conf.Language(15), id)\ndefault:\n    ret.Msg = err.Error()","preventionTips":["Verify doc IDs exist before opening old links or resuming saved state","Complete sync before relying on cross-device document references","Restore missing .sy files from backup/sync if data was deleted manually"],"tags":["go","kernel","tree","not-found"],"backgroundTag":"file-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"}