alibaba/open-code-review · error

--to is required when --from is specified

Error message

--to is required when --from is specified

What it means

validateDiffMode guard: --from was supplied without --to. A from/to diff range is only meaningful with both endpoints; one-sided ranges cannot define a reviewable diff, and mixing them with --commit is rejected separately. Raised by validateReviewOptions and validateDelegateOptions before any work starts.

Source

Thrown at cmd/opencodereview/shared_flags.go:97

		return values, cobra.ShellCompDirectiveNoFileComp
	}
}

// --- Validation functions ---

func validateDiffMode(from, to, commit string) error {
	modeCount := 0
	if from != "" || to != "" {
		modeCount++
	}
	if commit != "" {
		modeCount++
	}
	if modeCount > 1 {
		return fmt.Errorf("only one review mode allowed (--from/--to or --commit)")
	}
	if from != "" && to == "" {
		return fmt.Errorf("--to is required when --from is specified")
	}
	if to != "" && from == "" {
		return fmt.Errorf("--from is required when --to is specified")
	}
	return nil
}

func validateAudience(audience string) error {
	switch audience {
	case "human", "agent":
		return nil
	default:
		return fmt.Errorf("invalid --audience value %q: must be 'human' or 'agent'", audience)
	}
}

func validateOutputFormat(format string) (string, error) {
	normalized := strings.ToLower(strings.TrimSpace(format))

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Add the missing end ref: ocr review --from main --to HEAD
  2. Drop --from and use --commit SHA if a single commit was intended
  3. In scripts, guard: only emit --from when --to is also set
  4. Default --to to HEAD in your wrapper when the user gives only --from

Example fix

// before
ocr review --from main
// after
ocr review --from main --to HEAD
Defensive patterns

Strategy: validation

Validate before calling

if [ -n "$FROM" ] && [ -z "$TO" ]; then echo '--to required with --from'; exit 2; fi

Type guard

null

Try / catch

if ! ocr review --from "$FROM" ${TO:+--to "$TO"}; then case $? in *) echo 'pair --from with --to or use --commit';; esac; fi

Prevention

When it happens

Trigger: Running `ocr review --from main` (no --to) — the from != "" && to == "" branch in validateDiffMode, reached via validateReviewOptions or validateDelegateOptions.

Common situations: Users assuming --from alone means 'everything since this ref'; shell scripts building flags conditionally where --to was dropped by an unset variable; typos like --Too.

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 alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/ac35bb1aaed0f545. Report an issue: GitHub.