{"record":{"id":"7c934b65c7c5e43a","repo":"siyuan-note/siyuan","slug":"errindexing","errorCode":"ErrIndexing","errorMessage":"indexing","messagePattern":"indexing","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/tree.go","lineNumber":214,"sourceCode":"\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 {\n\t\t// boxID 未知时（如通用打开入口），遍历所有已打开的加密笔记本查找","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/tree.go#L196-L232","documentation":"ErrIndexing is the sentinel returned when the requested data is not yet available because the block index is being (re)built — the operation must be retried after indexing finishes. Handlers translate it to code 3 and the localized 'indexing' message (Conf.Language(56)) so the frontend shows a temporary state instead of an error.","triggerScenarios":"GetDocInfoInBox, LoadTreeByBlockIDWithReindexInBox, loadTreeByBlockIDInBox0, ReindexMissingNormalBlock and setGetBlockInfoError paths hit a block that exists in the doc but is not yet in the database during a reindex (kernel/api/block.go:371, :712); queries issued right after boot or after /api/filetree/refresh/reindex.","commonSituations":"Opening a large workspace and querying blocks immediately; a plugin/integration running right after startup before index queues drain; a doc created/edited while assets/FTS indexing is still in flight; triggering reindex then fetching docs concurrently.","solutions":["Wait for indexing to finish and retry the request — handlers return code 3 with Conf.Language(56) for this purpose","Poll /api/query/sql or block info until the block appears, with exponential backoff","Avoid issuing block queries immediately after boot or after triggering reindex; listen for index-complete push messages","Persist model.ErrIndexing semantics in your client as 'temporarily unavailable, retry' rather than a hard failure"],"exampleFix":"// before\nroot, err := model.GetBlock(block.RootID, tree)\nif err != nil { return err }\n\n// after\nif errors.Is(err, model.ErrIndexing) {\n    return apicontract.FailureWithText[apicontract.BlockInfoData](3, ret.Msg, model.Conf.Language(56))\n}","handlingStrategy":"retry","validationCode":"// TypeScript: wait for indexing before heavy queries\nawait new Promise(r => setTimeout(r, 1000)); // back off after boot/reindex\nconst info = await fetchPost('/api/block/getDocInfo', { id });\nif (info.code === 3) { /* still indexing: retry with backoff */ }","typeGuard":"function isIndexing(msg: string | null | undefined): boolean {\n  return msg === 'indexing';\n}","tryCatchPattern":"// Go\nif errors.Is(err, model.ErrIndexing) {\n    return apicontract.FailureWithText[apicontract.BlockInfoData](3, ret.Msg, model.Conf.Language(56))\n}","preventionTips":["Delay block queries until after workspace indexing completes; respect response code 3 as 'retry later'","Subscribe to kernel push messages indicating index progress before running automated queries","Avoid triggering reindex and immediate doc fetches in the same automation step"],"tags":["go","kernel","indexing","retry"],"backgroundTag":"resource-temporarily-unavailable","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"}