alibaba/open-code-review · error
invalid effort %q: must be one of %s
Error message
invalid effort %q: must be one of %s
What it means
ParseEffort validates the user-supplied effort level against the known presets (case-insensitively, via strings.ToLower). If the value is not one of the EffortNames() list, this error is returned describing the allowed values. Effort selects the review depth preset.
Source
Thrown at internal/config/template/effort.go:44
return []string{string(EffortLow), string(EffortMedium), string(EffortHigh)}
}
// EffortPreset is the concrete knob set an Effort level expands to.
type EffortPreset struct {
MaxReviewRounds int
}
var effortPresets = map[Effort]EffortPreset{
EffortLow: {MaxReviewRounds: 1},
EffortMedium: {MaxReviewRounds: 2},
EffortHigh: {MaxReviewRounds: 3},
}
// ParseEffort validates a user-supplied effort value.
func ParseEffort(s string) (Effort, error) {
e := Effort(strings.ToLower(s))
if _, ok := effortPresets[e]; !ok {
return "", fmt.Errorf("invalid effort %q: must be one of %s", s, strings.Join(EffortNames(), ", "))
}
return e, nil
}
// Preset returns the knob set for e.
func (e Effort) Preset() EffortPreset {
if p, ok := effortPresets[e]; ok {
return p
}
return effortPresets[EffortDefault]
}
// ApplyEffort overwrites the effort-controlled template scalars.
func (t *Template) ApplyEffort(e Effort) {
p := e.Preset()
t.MaxReviewRounds = p.MaxReviewRounds
}
View on GitHub (pinned to 5cf97d0d15)
Solutions
- Use one of the exact accepted names printed in the error (strings.Join(EffortNames(), ", ")) — e.g. `ocr review --effort max`
- Trim whitespace and check case is irrelevant (ToLower is applied, so case is fine but spaces are not)
- Upgrade/downgrade awareness: check `ocr --help` for the effort values supported by your installed version
- Grep internal/config/template/effort.go for effortPresets to see the authoritative list
Example fix
// before ocr review --effort extreme // after ocr review --effort max
Defensive patterns
Strategy: validation
Validate before calling
import "strings"
var validEfforts = map[string]bool{"low": true, "medium": true, "high": true} // match EffortNames()
func validEffort(s string) bool { return validEfforts[strings.ToLower(strings.TrimSpace(s))] } Try / catch
eff, err := template.ParseEffort(flagValue)
if err != nil {
var inv *template.EffortError // or check message prefix "invalid effort"
fmt.Fprintf(os.Stderr, "usage: ocr review --effort <%s>\n", strings.Join(template.EffortNames(), "|"))
os.Exit(2)
} Prevention
- Copy effort values from `ocr review --help`, not from memory
- Trim and avoid whitespace in config values for effort
- When upgrading ocr, diff the EffortNames list for renames
- Use shell completion or a wrapper script that restricts effort to known values
When it happens
Trigger: setConfigValue, resolveEffort, or validateReviewOptions receives an effort string such as "high", "extreme", "", or " maximum" (leading space) that is not in effortPresets.
Common situations: Typo in --effort flag (e.g. `higth`); an old effort name removed/renamed in a newer ocr version; a config file key set to a value copied from different tooling; whitespace around the value in YAML/JSON config.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- invalid max_tokens in app config: must be a positive integer
- invalid config: %w
- unsupported extension %q, only .md/.txt/.markdown allowed
- max_tokens must be positive
- max_tool_request_times must be positive
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/1464067b40fd38ae.
Report an issue: GitHub.