{"record":{"id":"0c2eca8d7f89ece1","repo":"siyuan-note/siyuan","slug":"notebook-is-required-0c2eca","errorCode":null,"errorMessage":"--notebook is required","messagePattern":"--notebook is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/import.go","lineNumber":45,"sourceCode":"\nvar importCmd = &cobra.Command{\n\tUse:   \"import\",\n\tShort: \"Import files\",\n}\n\nvar importMdCmd = &cobra.Command{\n\tUse:   \"md --file <path> --notebook <id>\",\n\tShort: \"Import Markdown file or directory\",\n\tRunE: func(cmd *cobra.Command, args []string) error {\n\t\tfilePath, _ := cmd.Flags().GetString(\"file\")\n\t\tnotebook, _ := cmd.Flags().GetString(\"notebook\")\n\t\ttoPath, _ := cmd.Flags().GetString(\"path\")\n\t\thpath, _ := cmd.Flags().GetString(\"hpath\")\n\t\tif filePath == \"\" {\n\t\t\treturn fmt.Errorf(\"--file is required\")\n\t\t}\n\t\tif notebook == \"\" {\n\t\t\treturn fmt.Errorf(\"--notebook is required\")\n\t\t}\n\n\t\tabsPath, err := filepath.Abs(filePath)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\ttargetPath, err := resolvePath(notebook, toPath, hpath)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tif dryRun {\n\t\t\tif err := model.ValidateImportFromLocalPath(notebook, absPath, targetPath); err != nil {\n\t\t\t\treturn formatNotebookWriteError(notebook, err)\n\t\t\t}\n\t\t\tfmt.Printf(\"[dry-run] Would import Markdown from \\\"%s\\\" to notebook %s\\n\", filePath, notebook)\n\t\t\treturn nil\n\t\t}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/import.go#L27-L63","documentation":"Argument validation in the cobra importMd RunE: fires when the --notebook flag is empty. Importing a Markdown file or directory requires the target notebook ID into which the .sy documents are created; running `import md` with only --file is the faulting usage.","triggerScenarios":"Running `siyuan import --file <path>` without --notebook or with an empty value.","commonSituations":"Developer uses the notebook name instead of its ID (e.g. \"My Notes\" rather than \"20240101123456-abcdefg\"); forgetting the flag entirely in scripts; notebook deleted so its ID variable is empty.","solutions":["Re-run with --notebook <notebook-id>; get the ID from `siyernel notebook list` / the notebook ls command","Copy the exact notebook ID (timestamp-random format) from the UI or API /api/notebook/lsNotebooks","Ensure the variable holding the notebook ID is non-empty"],"exampleFix":"// before\nimport --file ~/notes.md\n// after\nimport --file ~/notes.md --notebook 20240101123456-abcdefg","handlingStrategy":"validation","validationCode":"if [ -z \"$NB_ID\" ]; then echo \"--notebook is required (use the notebook ID, not its name)\" >&2; exit 1; fi\nsiyuan import --file \"$SRC_FILE\" --notebook \"$NB_ID\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use the notebook ID (timestamp-random format), never the display name","Fetch IDs from /api/notebook/lsNotebooks before scripting imports","Re-verify the notebook still exists if the ID came from an old script"],"tags":["cli","missing-flag","import"],"backgroundTag":"missing-required-flag","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"}