alibaba/open-code-review · error

model is required

Error message

model is required

What it means

After validating the provider name, applyCustomProviderConfig resolves the model via result.resolvedModel() and refuses to persist a custom provider entry with no model. Custom providers store models in the entry, so an empty model would leave the provider unusable for review requests.

Source

Thrown at cmd/opencodereview/provider_cmd.go:163

	fmt.Printf("Model: %s\n", result.model)

	fmt.Println("\nTesting connection...")
	if err := runLLMTest(); err != nil {
		fmt.Fprintf(os.Stderr, "Connection test failed: %v\n", err)
		fmt.Fprintln(os.Stderr, "Configuration has been saved. Fix the issue and run 'ocr llm test' to re-verify.")
		return nil
	}

	return nil
}

func applyCustomProviderConfig(configPath string, cfg *Config, result providerTUIResult) error {
	if result.provider == "" {
		return fmt.Errorf("provider name is required")
	}
	model := result.resolvedModel()
	if model == "" {
		return fmt.Errorf("model is required")
	}

	if cfg.CustomProviders == nil {
		cfg.CustomProviders = make(map[string]ProviderEntry)
	}

	entry := cfg.CustomProviders[result.provider]
	entry.Model = model
	if len(result.models) > 0 {
		entry.Models = append([]string(nil), result.models...)
	}
	entry.Models = ensureModelInList(entry.Models, model)
	if result.url != "" {
		entry.URL = result.url
	}
	if result.protocol != "" {
		entry.Protocol = result.protocol
	}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Pick or type a model in the provider wizard before confirming
  2. Verify resolvedModel() is populated (session model pick or typed model) before saving
  3. Pre-seed the custom provider entry's Models list so a sensible default can resolve

Example fix

// before
result := providerTUIResult{provider: "my-llm"} // model empty
// after
result := providerTUIResult{provider: "my-llm", model: "gpt-4o"}
err := applyCustomProviderConfig(path, cfg, result)
Defensive patterns

Strategy: validation

Validate before calling

if result.provider == "" || result.resolvedModel() == "" {
    return errors.New("provider and model must both be selected")
}
applyCustomProviderConfig(configPath, cfg, result)

Type guard

func isCompleteCustomSelection(r providerTUIResult) bool {
    return r.provider != "" && r.resolvedModel() != ""
}

Prevention

When it happens

Trigger: The wizard result has a provider but resolvedModel() returns "" — neither the picked model nor the typed model was set; exercised by TestApplyCustomProviderConfig_MissingModel.

Common situations: User selects a provider in the wizard but skips/empties the model selection; a custom entry defined only by URL without any model list; a TUI change stops propagating the chosen model into resolvedModel.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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