{"record":{"id":"981e16662e93ef89","repo":"siyuan-note/siyuan","slug":"file-is-required-981e16","errorCode":null,"errorMessage":"--file is required","messagePattern":"--file is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/cli/cmd/import.go","lineNumber":42,"sourceCode":"\n\t\"github.com/spf13/cobra\"\n)\n\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\n\t\tif dryRun {\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}\n\n\t\tif err := model.ImportFromLocalPath(notebook, absPath, resolvePath(notebook, toPath, hpath)); err != nil {\n\t\t\treturn formatNotebookWriteError(notebook, err)\n\t\t}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/cli/cmd/import.go#L24-L60","documentation":"Thrown by the `import md` subcommand when the `--file` flag is empty. The flag names a host Markdown file or directory to import; it is resolved to an absolute path afterward. Without it there is nothing to import.","triggerScenarios":"Running `siyuan import md --notebook <id>` with no `--file`, or `--file` empty. The check runs before the `--notebook` check, so `--file` is validated first.","commonSituations":"Typing the command without the source path; passing a glob that the shell expanded to nothing; scripting with an unset source variable.","solutions":["Supply the source: `siyuan import md --file ./notes/ --notebook <id>`","Ensure the path exists on the host (it is resolved via `filepath.Abs`, not workspace-relative)"],"exampleFix":"// before\nsiyuan import md --notebook 20240101\n// after\nsiyuan import md --file ./notes/intro.md --notebook 20240101","handlingStrategy":"validation","validationCode":"if file == \"\" {\n    return errors.New(\"source file or directory is required for import md\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember `--file` is host-absolute/resolved, not workspace-relative","Supply `--file` and `--notebook` together","Verify the source exists before importing"],"tags":["cli","validation","missing-argument","import","go","siyuan"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}