alibaba/open-code-review · error

invalid effort : must be one of

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.

Solutions

  1. Use one of the exact accepted names printed in the error (strings.Join(EffortNames(), ", ")) — e.g. `ocr review --effort max`
  2. Trim whitespace and check case is irrelevant (ToLower is applied, so case is fine but spaces are not)
  3. Upgrade/downgrade awareness: check `ocr --help` for the effort values supported by your installed version
  4. 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

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


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/1464067b40fd38ae. Report an issue: GitHub.

Appendix: 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)