alibaba/open-code-review · error
--preview and --resume cannot be used together
Error message
--preview and --resume cannot be used together
What it means
validateReviewOptions rejects combining --preview with --resume because they configure contradictory session behavior: preview runs a fresh lightweight pass while resume continues an existing session identified by an ID.
Source
Thrown at cmd/opencodereview/shared_flags.go:129
}
}
func validateOutputFormat(format string) (string, error) {
normalized := strings.ToLower(strings.TrimSpace(format))
switch normalized {
case "text", "json", "sarif":
return normalized, nil
default:
return "", fmt.Errorf("invalid --format value %q: must be 'text', 'json', or 'sarif'", format)
}
}
func validateReviewOptions(opts *reviewOptions) error {
if err := validateDiffMode(opts.from, opts.to, opts.commit); err != nil {
return err
}
if opts.preview && opts.resume != "" {
return fmt.Errorf("--preview and --resume cannot be used together")
}
if err := validateAudience(opts.audience); err != nil {
return err
}
normalizedFormat, err := validateOutputFormat(opts.outputFormat)
if err != nil {
return err
}
opts.outputFormat = normalizedFormat
const minMaxTools = 50
if opts.maxTools < 0 {
return fmt.Errorf("--max-tools must be a non-negative integer (0 means use template default)")
}
if opts.maxTools > 0 && opts.maxTools < minMaxTools {
fmt.Fprintf(os.Stderr, "[ocr] --max-tools %d is below minimum %d, using %d\n", opts.maxTools, minMaxTools, minMaxTools)
opts.maxTools = minMaxTools
}
if opts.maxGitProcs < 0 {View on GitHub (pinned to 5cf97d0d15)
Solutions
- Drop --preview to resume the session: ocr review --resume <id>
- Drop --resume to run a fresh preview: ocr review --preview ...
- In wrappers, make --preview and --resume mutually exclusive in your own arg parsing
- Start a new session instead of resuming if preview semantics are what you want
Example fix
// before ocr review --from main --to HEAD --preview --resume sess_123 // after ocr review --from main --to HEAD --resume sess_123
Defensive patterns
Strategy: validation
Validate before calling
if [ -n "$RESUME" ] && [ "$PREVIEW" = "1" ]; then echo '--preview and --resume are mutually exclusive'; exit 2; fi
Type guard
null
Try / catch
if ! ocr review "$@" 2>err.log; then grep -q 'preview and --resume cannot be used together' err.log && echo 'Drop --preview or --resume'; fi
Prevention
- Treat --preview and --resume as exclusive modes in your own arg parser
- Build flag arrays per mode instead of appending globally
- Document in wrapper scripts which mode each alias uses
- Resume existing sessions without preview; use preview only for fresh runs
When it happens
Trigger: Running `ocr review --preview --resume <id>` — the opts.preview && opts.resume != "" branch, reached from the review subcommand's anonymous option-building caller.
Common situations: Shell aliases or wrappers that hardcode --preview while the user adds --resume; scripts reusing a flag array across modes; misunderstanding preview as compatible with session continuation.
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
- only one review mode allowed (--from/--to or --commit)
- --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
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/7d068c3188950dbb.
Report an issue: GitHub.