siyuan-note/siyuan · error

--old is required

Error message

--old is required

What it means

Argument validation in the cobra tagRename RunE: fires when the --old flag is empty (the --new check follows). Renaming a tag requires the existing label; supplying only --new or no flags is the faulting usage.

Solutions

  1. Provide both flags: `siyuan tag rename --old oldtag --new newtag`
  2. Verify the old tag exists via a tag listing before renaming
  3. Ensure shell variables for old/new are non-empty

Example fix

// before
siyuan tag rename --new newtag
// after
siyuan tag rename --old oldtag --new newtag
Defensive patterns

Strategy: validation

Validate before calling

if [ -z "$OLD" ]; then echo "--old is required" >&2; exit 2; fi
siyuan tag rename --old "$OLD" --new "$NEW"

Try / catch

if ! siyuan tag rename --old "$OLD" --new "$NEW"; then
  echo "rename failed; verify both flags" >&2
fi

Prevention

When it happens

Trigger: Running `siyuan tag rename` without `--old`, or with `--old ""`.

Common situations: Providing only `--new` assuming rename infers the source; quoting mistakes that drop the flag value; scripting where the old-label variable is empty.

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/ad2b8ea315abfc46. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/tag.go:82

			return nil
		}

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

var tagRenameCmd = &cobra.Command{
	Use:   "rename --old <old-label> --new <new-label>",
	Short: "Rename a tag",
	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 tag \"%s\" to \"%s\"\n", oldLabel, newLabel)
			return nil
		}

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

View on GitHub (pinned to 9f775e8a12)