alibaba/open-code-review · error

provider and model are required

Error message

provider and model are required

What it means

applyOfficialProviderConfig requires both a provider name and a model before persisting an official provider selection. When the provider name is empty, the wizard produced no usable selection at all, so the function returns the combined 'provider and model are required' message.

Source

Thrown at cmd/opencodereview/provider_cmd.go:262

	if apiKey != "" || strings.TrimSpace(apiKeyCmd) != "" {
		return nil
	}
	switch {
	case isPreset && preset.AmbientAuth:
		return nil
	case isPreset && preset.EnvVar != "":
		if os.Getenv(preset.EnvVar) == "" {
			return fmt.Errorf("API key is required for provider %s (configure it, set providers.%s.api_key_cmd, or set $%s)", providerName, providerName, preset.EnvVar)
		}
		return nil
	default:
		return fmt.Errorf("API key is required for provider %s (configure it or set providers.%s.api_key_cmd)", providerName, providerName)
	}
}

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

	preset, isPreset := llm.LookupProvider(result.provider)

	if err := checkAPIKeyRequirement(result.provider, result.apiKey, cfg.Providers[result.provider].APIKeyCmd, preset, isPreset); err != nil {
		return err
	}

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

	entry := cfg.Providers[result.provider]
	entry.Model = model

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Complete the provider wizard and select a provider before saving
  2. Ensure providerTUIResult.provider is set when constructing the result programmatically
  3. Treat wizard cancellation as a clean exit rather than calling apply

Example fix

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

Strategy: validation

Validate before calling

if result.provider == "" {
    return errors.New("no provider selected; rerun 'ocr config provider'")
}
applyOfficialProviderConfig(configPath, cfg, result)

Type guard

func hasProviderSelection(r providerTUIResult) bool { return r.provider != "" }

Prevention

When it happens

Trigger: applyOfficialProviderConfig is entered with result.provider == "" — the wizard result carries no provider; covered by TestApplyOfficialProviderConfig_MissingFields.

Common situations: Cancelling the official-provider wizard; a non-interactive path that builds providerTUIResult without setting provider; regression in the TUI that clears the selection before apply.

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/ecb39c21ecad1d61. Report an issue: GitHub.