siyuan-note/siyuan · error

--id and --notebook are required

Error message

--id and --notebook are required

What it means

The `document move` cobra subcommand requires both --id (the document to move) and --notebook (the destination notebook). The handler returns this error when either is empty, before loading the source tree and before resolving the destination path via resolveDocumentMovePath. The --path and --hpath flags are optional and only specify where inside the destination notebook the document lands.

Source

Thrown at kernel/cli/cmd/document.go:217

		if err := model.RenameDoc(tree.Box, tree.Path, title); err != nil {
			return err
		}
		model.AppendPushRenameEntry(tree.Box, tree.Path, title)
		fmt.Println(id)
		return nil
	},
}

var documentMoveCmd = &cobra.Command{
	Use:   "move --id <id> --notebook <id>",
	Short: "Move a document to another notebook",
	RunE: func(cmd *cobra.Command, args []string) error {
		id, _ := cmd.Flags().GetString("id")
		toNotebook, _ := cmd.Flags().GetString("notebook")
		toPath, _ := cmd.Flags().GetString("path")
		hpath, _ := cmd.Flags().GetString("hpath")
		if id == "" || toNotebook == "" {
			return fmt.Errorf("--id and --notebook are required")
		}

		tree, err := model.LoadTreeByBlockID(id)
		if err != nil {
			return err
		}
		targetPath, err := resolveDocumentMovePath(toNotebook, toPath, hpath, tree.HPath)
		if err != nil {
			return err
		}

		if dryRun {
			fmt.Printf("[dry-run] Would move document %s to notebook %s\n", id, toNotebook)
			return nil
		}

		if err := model.MoveDocs([]string{tree.Path}, toNotebook, targetPath, nil); err != nil {
			return err

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Supply both flags: `siyuan document move --id <id> --notebook <destNotebookId>`.
  2. Look up IDs via `document list` / `notebook list`.
  3. Guard both variables in scripts and abort if either is empty.
  4. Use `--dry-run` to preview the resolved destination before moving.
  5. Verify flags with `siyuan document move --help`.

Example fix

// before
siyuan document move --id 20240101000000-abc1234
// after
siyuan document move --id 20240101000000-abc1234 --notebook 20240202000000-dest
Defensive patterns

Strategy: validation

Validate before calling

[ -n "$DOC_ID" ] && [ -n "$DEST_NB" ] || { echo '--id and --notebook are required' >&2; exit 2; }
siyuan document move --dry-run --id "$DOC_ID" --notebook "$DEST_NB" && siyuan document move --id "$DOC_ID" --notebook "$DEST_NB"

Try / catch

if ! siyuan document move --id "$DOC_ID" --notebook "$DEST_NB" 2>err.txt; then
  grep -q 'required' err.txt && echo "pass both --id and --notebook" >&2
  exit 1
fi

Prevention

When it happens

Trigger: Running `siyuan document move --id <id>` without --notebook, or `--notebook <id>` without --id, or omitting both; passing empty values; scripting with unset variables.

Common situations: Forgetting the destination notebook; assuming the document moves within the same notebook by default; referencing shell variables that are empty; confusing the source notebook (derived from the doc) with the destination --notebook flag.

Related errors


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