{"record":{"id":"c36796dd55195000","repo":"siyuan-note/siyuan","slug":"opened-notebook-s-not-found","errorCode":null,"errorMessage":"opened notebook [%s] not found","messagePattern":"opened notebook \\[(.+?)\\] not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/api/import.go","lineNumber":168,"sourceCode":"\tif nil == box {\n\t\treturn apicontract.ImportSYAuto.FailureWithData(-1, \"opened notebook [\"+createdBoxID+\"] not found\", document)\n\t}\n\tevent := util.NewCmdResult(\"createnotebook\", 0, util.PushModeBroadcast)\n\tevent.Data = map[string]any{\"box\": box, \"existed\": existed}\n\tutil.PushEvent(event)\n\treturn apicontract.Success(apicontract.AutoImportedNotebook(notebookContract(box)))\n}, beginImportUpload[apicontract.ImportAutoData])\n\nfunc mountImportedNotebooks(ids []string) (ret []*model.Box, err error) {\n\tfor _, id := range ids {\n\t\tvar existed bool\n\t\texisted, err = model.Mount(id)\n\t\tif nil != err {\n\t\t\treturn\n\t\t}\n\t\tbox := model.Conf.Box(id)\n\t\tif nil == box {\n\t\t\treturn nil, fmt.Errorf(\"opened notebook [%s] not found\", id)\n\t\t}\n\t\tret = append(ret, box)\n\t\tevent := util.NewCmdResult(\"createnotebook\", 0, util.PushModeBroadcast)\n\t\tevent.Data = map[string]any{\"box\": box, \"existed\": existed}\n\t\tutil.PushEvent(event)\n\t}\n\treturn\n}\n\nvar continueImportSY = contractHandler(apicontract.ContinueImportSY, func(c *gin.Context, request apicontract.ContinueImportSYRequest) apicontract.Response[apicontract.ImportDocumentData] {\n\tzipPath, err := claimStagedSYImport(request.Token)\n\tif err != nil {\n\t\treturn apicontract.Failure[apicontract.ImportDocumentData](-1, err.Error())\n\t}\n\tdefer os.Remove(zipPath)\n\tif err = model.ImportSY(zipPath, request.Notebook, \"/\"); err != nil {\n\t\treturn apicontract.Failure[apicontract.ImportDocumentData](-1, err.Error())\n\t}","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/api/import.go#L150-L186","documentation":"mountImportedNotebooks mounts each imported notebook id and then looks it up in the open configuration via model.Conf.Box(id). If Mount succeeded but the configuration has no box entry for the id (mount returned without registering, or a race removed it), the import aborts with 'opened notebook [%s] not found'.","triggerScenarios":"After an .sy import that creates notebooks: model.Mount(id) succeeds but model.Conf.Box(id) returns nil — the notebook was not registered as an opened box, e.g. because the id is stale or the config write raced.","commonSituations":"Import archives containing notebooks whose ids collide with removed/closed notebooks; concurrent notebook close/remove while importing; corrupted conf.json missing the box entry.","solutions":["Re-run the import; a transient race between Mount and Conf.Box usually resolves on retry.","Check conf.json / the notebooks list to confirm the id actually exists after import; remove stale ids from the import set.","Reload the kernel configuration (or restart) so Conf sees the newly mounted notebook, then retry.","If Mount returns an error or the id refers to a deleted notebook, skip that id instead of treating it as opened."],"exampleFix":"// before\nexisted, err = model.Mount(id)\nif nil != err { return }\nbox := model.Conf.Box(id)\nif nil == box { return nil, fmt.Errorf(\"opened notebook [%s] not found\", id) }\n\n// after\nexisted, err = model.Mount(id)\nif nil != err { return }\nif err = model.ReloadBoxes(); err != nil { return }\nbox := model.Conf.Box(id)\nif nil == box { continue // skip stale id instead of failing the whole import }","handlingStrategy":"try-catch","validationCode":"const box = await getNotebook(id); if (!box) skipId(id) // confirm existence before import claim","typeGuard":null,"tryCatchPattern":"try { await runImport(ids) }\ncatch (e) { if (/opened notebook \\[.+\\] not found/.test(e.message)) { reloadConf(); retryImport(ids) } else throw e }","preventionTips":["Avoid importing notebooks whose ids collide with recently removed ones","Serialize import operations against notebook close/remove","Reload configuration after Mount before reading Conf.Box"],"tags":["import","notebook","race-condition"],"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"}