{"record":{"id":"d1cc7b2223ce2dee","repo":"alibaba/open-code-review","slug":"only-one-review-mode-allowed-from-to-or-com","errorCode":null,"errorMessage":"only one review mode allowed (--from/--to or --commit)","messagePattern":"only one review mode allowed \\(--from/--to or --commit\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared_flags.go","lineNumber":94,"sourceCode":"\nfunc completeEnum(values ...string) func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {\n\treturn func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {\n\t\treturn values, cobra.ShellCompDirectiveNoFileComp\n\t}\n}\n\n// --- Validation functions ---\n\nfunc validateDiffMode(from, to, commit string) error {\n\tmodeCount := 0\n\tif from != \"\" || to != \"\" {\n\t\tmodeCount++\n\t}\n\tif commit != \"\" {\n\t\tmodeCount++\n\t}\n\tif modeCount > 1 {\n\t\treturn fmt.Errorf(\"only one review mode allowed (--from/--to or --commit)\")\n\t}\n\tif from != \"\" && to == \"\" {\n\t\treturn fmt.Errorf(\"--to is required when --from is specified\")\n\t}\n\tif to != \"\" && from == \"\" {\n\t\treturn fmt.Errorf(\"--from is required when --to is specified\")\n\t}\n\treturn nil\n}\n\nfunc validateAudience(audience string) error {\n\tswitch audience {\n\tcase \"human\", \"agent\":\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid --audience value %q: must be 'human' or 'agent'\", audience)\n\t}\n}","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared_flags.go#L76-L112","documentation":"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.","triggerScenarios":"Passing --commit <sha> together with --from and/or --to on review or delegate subcommands (validateDiffMode is invoked from validateReviewOptions and validateDelegateOptions).","commonSituations":"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.","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"],"exampleFix":"// before\nocr review --from main --to HEAD --commit abc123\n// after\nocr review --from main --to HEAD","handlingStrategy":"validation","validationCode":"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; }","typeGuard":"null","tryCatchPattern":"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","preventionTips":["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"],"tags":["cli","flags","validation"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}