{"record":{"id":"2f50863e7abc02bc","repo":"siyuan-note/siyuan","slug":"errsytargetnotebookrequired","errorCode":"ErrSYTargetNotebookRequired","errorMessage":"target notebook required","messagePattern":"target notebook required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"kernel/model/import.go","lineNumber":167,"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":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/import.go#L149-L185","documentation":"ErrSYTargetNotebookRequired is a sentinel error returned by the auto-detect import path when autoDetect is on, notebook creation was not requested, and no target boxID was supplied — the kernel needs to know which existing notebook to import into. The API handler (kernel/api/import.go:172) checks errors.Is against it to stage the import for user selection instead of failing outright.","triggerScenarios":"Calling model.ImportSYAuto(zipPath, \"\", toPath) (or importSYAuto/importSY0 with autoDetect=true, createNotebook=false, boxID=\"\") for an archive that is not a notebook export, i.e. an ordinary document .sy.zip with no target notebook specified.","commonSituations":"Automation scripts calling the importSYAuto API endpoint without a notebook parameter; archives containing only documents so auto-detect cannot decide to create a notebook; frontends that omit the notebook field on first import attempt.","solutions":["Pass a valid target notebook (box) ID when calling ImportSYAuto / the import API","Handle errors.Is(err, model.ErrSYTargetNotebookRequired) by prompting the user to choose/create a target notebook (as kernel/api/import.go does with stageSYImport)","Set createNotebook=true if the intent is to import as a new notebook"],"exampleFix":"// before\ncreatedBoxID, notebook, err := model.ImportSYAuto(zipPath, \"\", toPath)\n// after\ncreatedBoxID, notebook, err := model.ImportSYAuto(zipPath, targetBoxID, toPath)\nif errors.Is(err, model.ErrSYTargetNotebookRequired) {\n    // prompt user for target notebook or stage selection\n}","handlingStrategy":"type-guard","validationCode":"// caller-side check before calling ImportSYAuto\nif autoDetect && !createNotebook && boxID == \"\" {\n    return ErrSYTargetNotebookRequired // fail fast locally or prompt for a notebook\n}","typeGuard":"func isTargetNotebookRequired(err error) bool {\n    return errors.Is(err, model.ErrSYTargetNotebookRequired)\n}","tryCatchPattern":"// Go caller (mirrors kernel/api/import.go:172)\ncreatedBoxID, notebook, err := model.ImportSYAuto(zipPath, boxID, toPath)\nif errors.Is(err, model.ErrSYTargetNotebookRequired) {\n    // stage the import and ask the user for a target notebook\n    return stageSYImport(zipPath)\n}","preventionTips":["Always supply a target notebook ID when importing documents (not notebooks)","Treat the sentinel as control flow: prompt the user rather than surfacing an error","Never compare error strings; use errors.Is against model.ErrSYTargetNotebookRequired"],"tags":["import","sentinel-error","missing-parameter","notebook"],"backgroundTag":"missing-required-argument","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}