siyuan-note/siyuan · error

--notebook is required

Error message

--notebook is required

What it means

Thrown by the `import md` subcommand when `--notebook` is empty. The notebook ID selects the destination box for the imported Markdown. The check runs after `--file`, so both flags must be supplied.

Source

Thrown at kernel/cli/cmd/import.go:45

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)
		}
		model.AppendPushReloadFiletreeEntry()
		fmt.Println("ok")
		return nil

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Find notebook IDs with `siyuan notebook list`
  2. Pass the ID: `siyuan import md --file ./notes.md --notebook <id>`

Example fix

// before
siyuan import md --file ./notes.md
// after
siyuan import md --file ./notes.md --notebook 20240101120000-abc
Defensive patterns

Strategy: validation

Validate before calling

if notebook == "" {
    out, _ := cmd.Output("siyuan", "notebook", "list")
    log.Fatalf("notebook ID required. Available:\n%s", out)
}

Prevention

When it happens

Trigger: Running `siyuan import md --file ./notes.md` with no `--notebook`. The RunE reads the notebook flag and returns the error before resolving the file path.

Common situations: Forgetting the destination notebook; using a notebook name instead of its ID; an unset env var holding the ID.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/0c2eca8d7f89ece1. Report an issue: GitHub.