siyuan-note/siyuan · error

--new is required

Error message

--new is required

What it means

Argument validation in the cobra bookmarkRename RunE: fires when the --new flag is empty after --old passed. Renaming a bookmark requires both the existing label (--old) and the target label (--new); supplying only --old is the faulting usage.

Solutions

  1. Supply the target label: bookmark rename --old "TODO" --new "Important"
  2. If the goal is deletion, use `bookmark remove --label <label>` instead of renaming to an empty string
  3. Verify shell variables are quoted and non-empty before invoking the command

Example fix

// before
siyuan bookmark rename --old "TODO" --new ""
// after
siyuan bookmark remove --label "TODO"
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$NEW" ]; then echo "--new is required (use bookmark remove to delete)" >&2; exit 1; fi
siyuan bookmark rename --old "$OLD" --new "$NEW"

Prevention

When it happens

Trigger: Running `bookmark rename --old "TODO"` without --new, or with `--new ""`; shell quoting issues that swallow the value (`--new "$NEW"` with NEW empty or containing only spaces).

Common situations: Bulk rename scripts where the new-label list is shorter than the old-label list; intending to clear/delete a bookmark via an empty new label (unsupported — use `bookmark remove` instead).

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


AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19). Data as JSON: /api/errors/a21a11547859a5e6. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/bookmark.go:104

		if err := model.RemoveBookmark(label); err != nil {
			return err
		}
		model.AppendPushReloadFiletreeEntry()
		return nil
	},
}

var bookmarkRenameCmd = &cobra.Command{
	Use:   "rename --old <old> --new <new>",
	Short: "Rename a bookmark",
	RunE: func(cmd *cobra.Command, args []string) error {
		oldLabel, _ := cmd.Flags().GetString("old")
		newLabel, _ := cmd.Flags().GetString("new")
		if oldLabel == "" {
			return fmt.Errorf("--old is required")
		}
		if newLabel == "" {
			return fmt.Errorf("--new is required")
		}

		if dryRun {
			fmt.Printf("[dry-run] Would rename bookmark \"%s\" to \"%s\"\n", oldLabel, newLabel)
			return nil
		}

		if err := model.RenameBookmark(oldLabel, newLabel); err != nil {
			return err
		}
		model.AppendPushReloadFiletreeEntry()
		return nil
	},
}

func printBookmarkTable(bookmarks *model.Bookmarks) {
	w := tabwriter.NewWriter(os.Stdout, 0, 0, 2, ' ', 0)
	fmt.Fprintln(w, "NAME\tCOUNT")

View on GitHub (pinned to 9f775e8a12)