siyuan-note/siyuan · error
--file is required
Error message
--file is required
What it means
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.
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
}
if dryRun {
fmt.Printf("[dry-run] Would import Markdown from \"%s\" to notebook %s\n", filePath, notebook)
return nil
}
if err := model.ImportFromLocalPath(notebook, absPath, resolvePath(notebook, toPath, hpath)); err != nil {
return formatNotebookWriteError(notebook, err)
}View on GitHub (pinned to 251596fc0d)
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)
Example fix
// before siyuan import md --notebook 20240101 // after siyuan import md --file ./notes/intro.md --notebook 20240101
Defensive patterns
Strategy: validation
Validate before calling
if file == "" {
return errors.New("source file or directory is required for import md")
} Prevention
- Remember `--file` is host-absolute/resolved, not workspace-relative
- Supply `--file` and `--notebook` together
- Verify the source exists before importing
When it happens
Trigger: Running `siyuan import md --notebook <id>` with no `--file`, or `--file` empty. The check runs before the `--notebook` check, so `--file` is validated first.
Common situations: Typing the command without the source path; passing a glob that the shell expanded to nothing; scripting with an unset source variable.
Related errors
AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12).
Data as JSON: /api/errors/981e16662e93ef89.
Report an issue: GitHub.