alibaba/open-code-review · error

--from is required when --to is specified

Error message

--from is required when --to is specified

What it means

Generic flag-consistency validation in validateDiffMode (shared by review and delegate options): it fires when --to was passed without --from. The from/to pair defines a diff range and is meaningless as a one-sided bound; passing only --to is treated as user error before any review work starts.

Source

Thrown at cmd/opencodereview/shared_flags.go:100

// --- 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))
	switch normalized {
	case "text", "json", "sarif":
		return normalized, nil

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Add the missing base ref: ocr review --from main --to HEAD
  2. Drop --to and use --commit SHA for a single-commit review
  3. In CI, fall back to a default base (e.g. origin/main) when the base ref variable is empty
  4. Use a wrapper that validates the pair before invoking ocr

Example fix

// before
BASE=""; ocr review --from "$BASE" --to HEAD   # BASE empty -> --from dropped by wrapper
// after
BASE="${BASE:-origin/main}"; ocr review --from "$BASE" --to HEAD
Defensive patterns

Strategy: validation

Validate before calling

if [ -n "$TO" ] && [ -z "$FROM" ]; then FROM="${BASE_REF:-origin/main}"; fi

Type guard

null

Try / catch

if ! ocr review ${FROM:+--from "$FROM"} --to "$TO" 2>err.log; then grep -q '\-\-from is required' err.log && ocr review --from origin/main --to "$TO"; fi

Prevention

When it happens

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

Common situations: Users thinking --to means 'review up to this commit' against an implicit base; scripts where --from was derived from an unset CI variable (e.g. missing base ref); truncated command lines.

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