siyuan-note/siyuan · error
--file is required
Error message
--file is required
What it means
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.
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
Example fix
// before import --notebook 20240101123456-abcdefg // after import --file ~/notes.md --notebook 20240101123456-abcdefg
Defensive patterns
Strategy: validation
Validate before calling
if [ -z "$SRC_FILE" ]; then echo "--file is required" >&2; exit 1; fi if [ ! -f "$SRC_FILE" ]; then echo "file not found: $SRC_FILE" >&2; exit 1; fi siyuan import --file "$SRC_FILE" --notebook "$NB_ID"
Prevention
- 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
When it happens
Trigger: Running `siyuan import` without --file or with an empty value.
Common situations: 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).
Understand the failure class
Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.
Related errors
- --notebook is required
- --av and --ids are required
- --av, --key, --item and --value are required
- --block is required for non-detached rows
- --id and --name are required
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/981e16662e93ef89.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/cli/cmd/import.go:42
"github.com/spf13/cobra"
)
var importCmd = &cobra.Command{
Use: "import",
Short: "Import files",
}
var importMdCmd = &cobra.Command{
Use: "md --file <path> --notebook <id>",
Short: "Import Markdown file or directory",
RunE: func(cmd *cobra.Command, args []string) error {
filePath, _ := cmd.Flags().GetString("file")
notebook, _ := cmd.Flags().GetString("notebook")
toPath, _ := cmd.Flags().GetString("path")
hpath, _ := cmd.Flags().GetString("hpath")
if filePath == "" {
return fmt.Errorf("--file is required")
}
if notebook == "" {
return fmt.Errorf("--notebook is required")
}
absPath, err := filepath.Abs(filePath)
if err != nil {
return err
}
targetPath, err := resolvePath(notebook, toPath, hpath)
if err != nil {
return err
}
if dryRun {
if err := model.ValidateImportFromLocalPath(notebook, absPath, targetPath); err != nil {
return formatNotebookWriteError(notebook, err)
}View on GitHub (pinned to 9f775e8a12)