{"record":{"id":"ac35bb1aaed0f545","repo":"alibaba/open-code-review","slug":"to-is-required-when-from-is-specified","errorCode":null,"errorMessage":"--to is required when --from is specified","messagePattern":"--to is required when --from is specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared_flags.go","lineNumber":97,"sourceCode":"\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}\n\nfunc validateOutputFormat(format string) (string, error) {\n\tnormalized := strings.ToLower(strings.TrimSpace(format))","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared_flags.go#L79-L115","documentation":"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.","triggerScenarios":"Running `ocr review --from main` (no --to) — the from != \"\" && to == \"\" branch in validateDiffMode, reached via validateReviewOptions or validateDelegateOptions.","commonSituations":"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.","solutions":["Add the missing end ref: ocr review --from main --to HEAD","Drop --from and use --commit SHA if a single commit was intended","In scripts, guard: only emit --from when --to is also set","Default --to to HEAD in your wrapper when the user gives only --from"],"exampleFix":"// before\nocr review --from main\n// after\nocr review --from main --to HEAD","handlingStrategy":"validation","validationCode":"if [ -n \"$FROM\" ] && [ -z \"$TO\" ]; then echo '--to required with --from'; exit 2; fi","typeGuard":"null","tryCatchPattern":"if ! ocr review --from \"$FROM\" ${TO:+--to \"$TO\"}; then case $? in *) echo 'pair --from with --to or use --commit';; esac; fi","preventionTips":["Always pass --from and --to as an inseparable pair","In scripts, default TO to HEAD when unset","Validate flag pairs before composing the command","Prefer --commit for single-commit reviews instead of a one-sided range"],"tags":["cli","flags","validation"],"backgroundTag":"missing-required-flag","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}