siyuan-note/siyuan · error

--left and --right are required

Error message

--left and --right are required

What it means

The `siyuan repo diff` command compares two repo snapshots and requires both `--left` and `--right` snapshot IDs. The RunE handler returns this error when either is empty, before calling model.DiffRepoSnapshots.

Solutions

  1. Re-run with both flags: `siyuan repo diff --left <id1> --right <id2>`
  2. Obtain both snapshot IDs (e.g. from snapshot list output) before diffing
  3. Check that neither ID variable is empty in generated command lines

Example fix

// before
siyuan repo diff --right 20240101120000-xyz
// after
siyuan repo diff --left 20240101120000-abc --right 20240101120000-xyz
Defensive patterns

Strategy: validation

Validate before calling

[ -n "$LEFT" ] && [ -n "$RIGHT" ] || { echo "repo diff: need --left and --right" >&2; exit 2; }
siyuan repo diff --left "$LEFT" --right "$RIGHT"

Type guard

function requireBoth(a, b) { if (!a || !b) throw new Error('--left and --right are required'); }

Try / catch

siyuan repo diff --left "$LEFT" --right "$RIGHT" || { echo 'diff needs two snapshot IDs'; }

Prevention

When it happens

Trigger: Running `siyuan repo diff` with only one of `--left`/`--right`, or neither; e.g. `siyuan repo diff --left <id>`.

Common situations: Assuming HEAD/current-workspace defaults exist (they do not; both endpoints are mandatory); scripts building the diff line where one endpoint 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/fd52379a82f10220. Report an issue: GitHub.

Appendix: source

Thrown at kernel/cli/cmd/repo.go:182

		if err := model.CheckoutRepoDirect(id); err != nil {
			return err
		}
		model.AppendPushReloadFiletreeEntry()
		model.AppendPushReloadUIEntry()
		fmt.Println("ok")
		return nil
	},
}

var repoDiffCmd = &cobra.Command{
	Use:   "diff --left <id> --right <id>",
	Short: "Diff two snapshots",
	RunE: func(cmd *cobra.Command, args []string) error {
		left, _ := cmd.Flags().GetString("left")
		right, _ := cmd.Flags().GetString("right")
		if left == "" || right == "" {
			return fmt.Errorf("--left and --right are required")
		}
		diff, err := model.DiffRepoSnapshots(left, right)
		if err != nil {
			return err
		}
		data, _ := json.MarshalIndent(diff, "", "  ")
		fmt.Println(string(data))
		return nil
	},
}

var repoSearchCmd = &cobra.Command{
	Use:   "search <keyword>",
	Short: "Search files in snapshots",
	Args:  cobra.MinimumNArgs(1),
	RunE: func(cmd *cobra.Command, args []string) error {
		keyword := args[0]
		page, _ := cmd.Flags().GetInt("page")

View on GitHub (pinned to 9f775e8a12)