{"record":{"id":"7484547bb3f59cb5","repo":"alibaba/open-code-review","slug":"from-is-required-when-to-is-specified","errorCode":null,"errorMessage":"--from is required when --to is specified","messagePattern":"--from is required when --to is specified","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/shared_flags.go","lineNumber":100,"sourceCode":"\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))\n\tswitch normalized {\n\tcase \"text\", \"json\", \"sarif\":\n\t\treturn normalized, nil","sourceCodeStart":82,"sourceCodeEnd":118,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/shared_flags.go#L82-L118","documentation":"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.","triggerScenarios":"Running `ocr review --to HEAD` (no --from) — the to != \"\" && from == \"\" branch in validateDiffMode, reached via validateReviewOptions or validateDelegateOptions.","commonSituations":"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.","solutions":["Add the missing base ref: ocr review --from main --to HEAD","Drop --to and use --commit SHA for a single-commit review","In CI, fall back to a default base (e.g. origin/main) when the base ref variable is empty","Use a wrapper that validates the pair before invoking ocr"],"exampleFix":"// before\nBASE=\"\"; ocr review --from \"$BASE\" --to HEAD   # BASE empty -> --from dropped by wrapper\n// after\nBASE=\"${BASE:-origin/main}\"; ocr review --from \"$BASE\" --to HEAD","handlingStrategy":"validation","validationCode":"if [ -n \"$TO\" ] && [ -z \"$FROM\" ]; then FROM=\"${BASE_REF:-origin/main}\"; fi","typeGuard":"null","tryCatchPattern":"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","preventionTips":["Default the base ref (e.g. origin/main) in CI environments","Never let an unset variable silently drop --from (use ${VAR:?} or defaults)","Pass range flags together from a single function","Validate the pair before invoking ocr"],"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"}