{"record":{"id":"aa1a49227e5cce3f","repo":"siyuan-note/siyuan","slug":"errboxunindexed","errorCode":"ErrBoxUnindexed","errorMessage":"notebook unindexed","messagePattern":"notebook unindexed","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/tree.go","lineNumber":215,"sourceCode":"\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 {\n\t\t// boxID 未知时（如通用打开入口），遍历所有已打开的加密笔记本查找\n\t\tfor _, encBoxID := range treenode.GetOpenedEncryptedBoxIDs() {","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/tree.go#L197-L233","documentation":"ErrBoxUnindexed is a sentinel error in the SiYuan kernel's model package meaning the requested notebook (box) exists and is open, but its content has not been indexed yet, so tree/block lookups cannot be served from the index. The kernel throws it instead of silently rebuilding the index because indexing is expensive and the UI is separately notified. Callers such as the block API treat it as 'user already warned' and suppress a duplicate error message.","triggerScenarios":"Calling load-tree or block lookup APIs (e.g. /api/filetree/getDoc, setGetBlockInfoError paths, indexTreeInFilesystem0) with a block ID whose notebook has no index yet — typically right after opening a workspace, re-enabling a closed notebook, or before the initial indexing pass finishes.","commonSituations":"Starting the kernel and immediately querying blocks; switching notebooks that were closed and reopened; a workspace restored from backup or sync where blocks/index tables are still being rebuilt.","solutions":["Wait for indexing to finish: retry after the notebook's index queue drains, or call the index API (e.g. /api/filetree/index) for the box first","Check the notebook is open and indexed via /api/notebook/lsNotebooks before issuing block/tree lookups","If the index is persistently missing, trigger a full reindex (Reindex / rebuildIndex) and retry","Handle the sentinel with errors.Is(err, model.ErrBoxUnindexed) and rely on the already-pushed UI message instead of surfacing a new error"],"exampleFix":"// before\nmsg := err.Error()\n// after\nif errors.Is(err, model.ErrBoxUnindexed) {\n    return // 提示已在加载时推送，忽略即可\n}","handlingStrategy":"retry","validationCode":"const nb = notebooks.find(nb => nb.id === boxID); if (!nb || nb.closed) abort(); /* else wait for indexing queue to drain before querying */","typeGuard":"func isBoxUnindexed(err error) bool { return errors.Is(err, model.ErrBoxUnindexed) }","tryCatchPattern":"if errors.Is(err, model.ErrBoxUnindexed) {\n    // UI 提示已推送，静默等待索引完成或稍后重试\n    return nil\n}","preventionTips":["Wait for initial indexing to complete before issuing block/tree queries after boot","Reopen/re-index a notebook explicitly after closing or restoring it","Poll notebook status instead of assuming index readiness"],"tags":["go","notebook","indexing"],"backgroundTag":"invalid-state-transition","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"}