{"record":{"id":"271c5e359d1bcb40","repo":"siyuan-note/siyuan","slug":"query-notebook-failed-271c5e","errorCode":null,"errorMessage":"Query notebook failed","messagePattern":"Query notebook failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/import.go","lineNumber":285,"sourceCode":"\t\treturn\n\t}\n\tif autoDetect {\n\t\tif importedMetadataErr != nil {\n\t\t\terr = errors.New(Conf.Language(199))\n\t\t\treturn\n\t\t}\n\t\tcreateNotebook = notebookExport\n\t}\n\tif !createNotebook && notebookExport {\n\t\terr = errors.New(Conf.Language(373))\n\t\treturn\n\t}\n\tif autoDetect && !createNotebook && boxID == \"\" {\n\t\terr = ErrSYTargetNotebookRequired\n\t\treturn\n\t}\n\tif !createNotebook && nil == Conf.Box(boxID) {\n\t\terr = errors.New(Conf.Language(0))\n\t\treturn\n\t}\n\tif createNotebook {\n\t\tif importedBoxConf != nil && importedBoxConf.Name != \"\" {\n\t\t\tname = importedBoxConf.Name\n\t\t}\n\t\tif !precreatedBox {\n\t\t\tboxID, err = CreateBox(util.RemoveInvalid(name))\n\t\t\tif err != nil {\n\t\t\t\treturn \"\", err\n\t\t\t}\n\t\t}\n\t\tcreatedBoxID = boxID\n\t\tdefer func() {\n\t\t\tif err == nil {\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttreenode.RemoveBlockTreesByBoxID(boxID)","sourceCodeStart":267,"sourceCodeEnd":303,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/afa823b6b4e4f183511e0bc0a3be93caa94c7c97/kernel/model/import.go#L267-L303","documentation":"When importing into an existing notebook (createNotebook=false), importSY0 looks up the target with Conf.Box(boxID); a nil result means no notebook with that ID is configured in the current workspace, and the import fails with the generic Language(0) message 'Query notebook failed'. The real cause - nonexistent target notebook - is only implicit in the message.","triggerScenarios":"POST /api/import/importSY (or importSYAuto) whose 'notebook' parameter references a boxID that does not exist right now: deleted before the import ran, never created in this workspace, belongs to a different workspace, or a race with notebook removal.","commonSituations":"Plugins/automation caching a stale notebook ID from an earlier session. The user deleted the target notebook between choosing it and confirming import. Kernel pointed at a different workspace directory than expected (Settings - About - Workspace).","solutions":["List the actual notebooks (GET /api/notebook/lsNotebooks) and retry with a valid id","If the notebook was expected to exist, check that SiYuan is running against the right workspace and that the notebook is not closed/removed","Create the target notebook first (POST /api/notebook/createNotebook) if it should be new"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if model.Conf.Box(boxID) == nil {\n    // refresh notebook list / fail fast before importing\n    return fmt.Errorf(\"target notebook %s does not exist\", boxID)\n}\nerr := model.ImportSY(zipPath, boxID, toPath)","typeGuard":"func isQueryNotebookFailed(err error) bool {\n    return err != nil && err.Error() == model.Conf.Language(0)\n}","tryCatchPattern":"if err := model.ImportSY(zipPath, boxID, toPath); err != nil {\n    if err.Error() == model.Conf.Language(0) {\n        // re-fetch notebooks via /api/notebook/lsNotebooks and retry with a fresh id\n    }\n}","preventionTips":["Always resolve the target notebook id at import time, never from a cached value","Handle notebook-deleted races in long-running clients by re-validating before submit","Confirm the kernel is pointed at the expected workspace before automated imports"],"tags":["siyuan","import","notebook","target-not-found","validation"],"backgroundTag":"target-notebook-not-found","analyzedSha":"afa823b6b4e4f183511e0bc0a3be93caa94c7c97","analyzedAt":"2026-08-18T17:04:10.865Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}