{"record":{"id":"2f50863e7abc02bc","repo":"siyuan-note/siyuan","slug":"errsytargetnotebookrequired","errorCode":"ErrSYTargetNotebookRequired","errorMessage":"target notebook required","messagePattern":"target notebook required","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/import.go","lineNumber":168,"sourceCode":"\t\t}\n\t\treturn ast.WalkContinue\n\t})\n\treturn\n}\n\nfunc ImportSY(zipPath, boxID, toPath string) (err error) {\n\tif isSYNotebookBundle(zipPath) {\n\t\treturn errors.New(Conf.Language(373))\n\t}\n\t_, err = importSY(zipPath, boxID, toPath, false, false)\n\treturn\n}\n\nfunc ImportSYNotebook(zipPath string) (boxID string, err error) {\n\treturn importSY(zipPath, \"\", \"/\", true, false)\n}\n\nvar ErrSYTargetNotebookRequired = errors.New(\"target notebook required\")\n\nfunc ImportSYAuto(zipPath, boxID, toPath string) (createdBoxID string, notebook bool, err error) {\n\tcreatedBoxID, err = importSY(zipPath, boxID, toPath, false, true)\n\tnotebook = err == nil && createdBoxID != boxID\n\treturn\n}\n\nfunc isSYNotebookExport(hasBoxConf, hasBoxDocMeta bool) bool {\n\treturn hasBoxConf || hasBoxDocMeta\n}\n\ntype importedSYSortDoc struct {\n\toldID      string\n\tnewID      string\n\tsourcePath string\n\thidden     bool\n}\n","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/import.go#L150-L186","documentation":"ErrSYTargetNotebookRequired is a sentinel error returned by importSY0 when autoDetect mode is on, notebook creation is disabled, and no target notebook (boxID) was supplied. ImportSYAuto is designed to figure out the import destination itself, but without either an explicit notebook, permission to create one, or auto-detection succeeding, there is no valid destination, so the caller (api/import.go) can check errors.Is(err, model.ErrSYTargetNotebookRequired) and fall back to staging the import for user selection.","triggerScenarios":"POST to the import API (model.ImportSYAuto) with request.Notebook == \"\" and a payload that is not a notebook bundle, so autoDetect cannot create a notebook (createNotebook false) and boxID is empty.","commonSituations":"API clients omitting the \"notebook\" field in the import request body while sending a document-tree zip; frontends that rely on the staged-import fallback flow triggering the error intentionally.","solutions":["Supply a valid target notebook ID in the import request's \"notebook\" field","If the destination should be a new notebook, use the import variant that creates a notebook (ImportSYNotebook)","Treat this sentinel as a control-flow signal: stage the import (as api/import.go does with stageSYImport) and let the user choose the destination","Validate the request body (notebook non-empty or notebook-creation enabled) before calling the API"],"exampleFix":"// before\nfetchPost(\"/api/import/importSY\", {\"path\": zipPath})\n// after\nfetchPost(\"/api/import/importSY\", {\"path\": zipPath, \"notebook\": \"20240101120000-abc\"})","handlingStrategy":"validation","validationCode":"if (!request.notebook && !allowCreateNotebook) { throw new Error(\"target notebook required\"); }","typeGuard":null,"tryCatchPattern":"createdBoxID, notebook, err := model.ImportSYAuto(path, reqNotebook, toPath); if errors.Is(err, model.ErrSYTargetNotebookRequired) { // stage the import and prompt the user for a destination }","preventionTips":["Always send the \"notebook\" field for document-tree import requests","Use the staged-import fallback when the destination should be user-selected","Validate request bodies at the API client layer before calling import"],"tags":["import","api","validation","sentinel-error"],"backgroundTag":"missing-required-argument","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"}