{"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\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}","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/cli/cmd/import.go#L24-L60","documentation":"The CLI `import` command (markdown import) requires --file, the source file to import. The flag is read first and this error is returned immediately when empty, before --notebook validation. Argument guard, no side effects.","triggerScenarios":"Running `siyuan import` without --file or with an empty value.","commonSituations":"Scripted import where the file variable is unset; importing many files and forgetting the flag on the first invocation; confusing --file with --path (the destination).","solutions":["Re-run with --file <source-file-path>, e.g. import --file notes.md --notebook 20240101123456-abcdefg","Verify the source file path variable is set and the file exists","Use --path for the destination block ID, not --file, when targeting an insertion point"],"exampleFix":"// before\nimport --notebook 20240101123456-abcdefg\n// after\nimport --file ~/notes.md --notebook 20240101123456-abcdefg","handlingStrategy":"validation","validationCode":"if [ -z \"$SRC_FILE\" ]; then echo \"--file is required\" >&2; exit 1; fi\nif [ ! -f \"$SRC_FILE\" ]; then echo \"file not found: $SRC_FILE\" >&2; exit 1; fi\nsiyuan import --file \"$SRC_FILE\" --notebook \"$NB_ID\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check the file exists before invoking import","Do not conflate --file (source) with --path (destination)","Wrap imports in a script that asserts all required flags"],"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"}