alibaba/open-code-review · error
only one review mode allowed (--from/--to or --commit)
Error message
only one review mode allowed (--from/--to or --commit)
What it means
validateDiffMode enforces that exactly one review mode is selected. When both the range mode (--from/--to) and single-commit mode (--commit) are supplied simultaneously, modeCount exceeds 1 and the command is rejected. The two modes are mutually exclusive interpretations of what to diff.
Source
Thrown at cmd/opencodereview/shared_flags.go:94
func completeEnum(values ...string) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
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)
}
}View on GitHub (pinned to 5cf97d0d15)
Solutions
- Remove --commit if you want to review a range, keep --from X --to Y
- Remove --from/--to if you want to review a single commit, keep --commit SHA
- In wrapper scripts, pass the range OR the commit, never both
- Read `ocr review --help` to confirm which mode your flags select
Example fix
// before ocr review --from main --to HEAD --commit abc123 // after ocr review --from main --to HEAD
Defensive patterns
Strategy: validation
Validate before calling
count=0; [ -n "$COMMIT" ] && count=$((count+1)); { [ -n "$FROM" ] || [ -n "$TO" ]; } && count=$((count+1)); [ "$count" -le 1 ] || { echo 'use either --from/--to or --commit, not both'; exit 2; } Type guard
null
Try / catch
if ! ocr review "$@" 2>err.log; then grep -q 'only one review mode allowed' err.log && echo 'Remove --commit or --from/--to from your command' ; fi
Prevention
- Build flag arrays per mode: either a range block or a commit block, never both
- In CI wrappers, branch explicitly on whether COMMIT is set
- Review the composed command with `set -x` before running
- Keep one canonical review invocation per script
When it happens
Trigger: Passing --commit <sha> together with --from and/or --to on review or delegate subcommands (validateDiffMode is invoked from validateReviewOptions and validateDelegateOptions).
Common situations: Scripts that always append --commit but get --from/--to injected from CI environment; copying an example command and adding an extra flag; shell wrappers accumulating flags across versions of the tool.
Understand the failure class
Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.
Related errors
- --to is required when --from is specified
- --from is required when --to is specified
- invalid --audience value %q: must be 'human' or 'agent'
- invalid --format value %q: must be 'text', 'json', or 'sarif
- --preview and --resume cannot be used together
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/d1cc7b2223ce2dee.
Report an issue: GitHub.