{"record":{"id":"2563bd4b149693dd","repo":"siyuan-note/siyuan","slug":"errboxnotfound","errorCode":"ErrBoxNotFound","errorMessage":"notebook not found","messagePattern":"notebook not found","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/tree.go","lineNumber":210,"sourceCode":"\t\tif data, err = DecryptFile(boxID, relPath, dek, data); err != nil {\n\t\t\tlogging.LogErrorf(\"decrypt tree [path=%s] failed: %s\", localPath, err)\n\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}","sourceCodeStart":192,"sourceCodeEnd":228,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/tree.go#L192-L228","documentation":"ErrBoxNotFound is the sentinel error returned when a notebook (box) ID does not exist in the workspace — e.g. lookups of the notebook directory fail. API handlers compare with errors.Is to translate it into client-facing data such as an 'unavailable notebook' payload for attribute-view item creation.","triggerScenarios":"model.CreateAttributeViewItemDocs (or other notebook-consuming operations) is called with a boxID that has no matching notebook in the workspace, or a save-config resolution derives a notebook ID that does not exist; handlers at kernel/api/av.go:361 and kernel/api/av_contract_render.go:66 map it to AVUnavailableNotebook.","commonSituations":"Client caches a stale notebook ID after the notebook was deleted or its .si folder removed; typo'd or malformed notebook ID in an API call; notebook added on another profile/workspace; attribute view references a doc whose notebook was removed.","solutions":["List notebooks (GET /api/notebook/lsNotebooks) and confirm the boxID exists; correct the ID in the caller","Re-add or reopen the notebook if it was removed from the workspace","Refresh any cached notebook IDs in your integration before calling CreateAttributeViewItemDocs","Handle errors.Is(err, model.ErrBoxNotFound) in your client to surface 'unavailable notebook' instead of a raw error"],"exampleFix":"// before\nvalue, err := model.CreateAttributeViewItemDocs(avID, blockID, mode, ids)\nif err != nil { return err }\n\n// after\nif err != nil {\n    if errors.Is(err, model.ErrBoxNotFound) {\n        return apicontract.CreateAttributeViewItemDocs.FailureWithData(1, \"\",\n            apicontract.NewAVCreateItemDocsResultError(apicontract.AVUnavailableNotebook{UnavailableNotebook: true}))\n    }\n    return err\n}","handlingStrategy":"try-catch","validationCode":"// TypeScript: verify notebook exists before the call\nconst boxes = await fetchPost('/api/notebook/lsNotebooks', {});\nif (!boxes.data.notebooks.includes(boxID)) throw new Error('notebook missing: ' + boxID);","typeGuard":"function isBoxNotFound(err: unknown): err is Error {\n  return err instanceof Error && err.message === 'notebook not found';\n}","tryCatchPattern":"// Go\nif errors.Is(err, model.ErrBoxNotFound) {\n    return apicontract.CreateAttributeViewItemDocs.FailureWithData(1, \"\",\n        apicontract.NewAVCreateItemDocsResultError(apicontract.AVUnavailableNotebook{UnavailableNotebook: true}))\n}","preventionTips":["Always resolve notebook IDs from lsNotebooks instead of hard-coding them","Refresh cached notebook IDs after any notebook add/remove","Handle ErrBoxNotFound explicitly in API clients to surface 'unavailable notebook'"],"tags":["go","kernel","notebook","not-found"],"backgroundTag":"entity-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"}