alibaba/open-code-review · error

resolve OCR config file: provider %q is not configured in %s

Error message

resolve OCR config file: provider %q is not configured in %s section because the config file does not exist

What it means

When an explicit Provider is requested, the resolver requires an entry in the OCR config file; there is no env fallback for that path. If tryOCRConfig reports ok=false — which for this path effectively means the config file does not exist or the provider has no usable entry — the resolver fails with a message naming the expected section: "providers" for built-in presets (LookupProvider hit) or "custom_providers" for anything else.

Source

Thrown at internal/llm/resolver.go:121

	// unparseable OCR_LLM_EXTRA_HEADERS abort resolution *after* api_key_cmd
	// already prompted 1Password/pinentry/Touch ID for a credential that then
	// gets discarded.
	env, err := parseEnvOverrides()
	if err != nil {
		return ResolvedEndpoint{}, err
	}

	if opts.Provider != "" {
		ep, ok, err := tryOCRConfig(configPath, opts)
		if err != nil {
			return ResolvedEndpoint{}, fmt.Errorf("resolve OCR config file: %w", err)
		}
		if !ok {
			section := "custom_providers"
			if _, isPreset := LookupProvider(opts.Provider); isPreset {
				section = "providers"
			}
			return ResolvedEndpoint{}, fmt.Errorf("resolve OCR config file: provider %q is not configured in %s section because the config file does not exist", opts.Provider, section)
		}
		return finalizeResolvedEndpoint("OCR config file", ep, env), nil
	}

	strategies := []struct {
		name string
		fn   func() (ResolvedEndpoint, bool, error)
	}{
		{"OCR config file", func() (ResolvedEndpoint, bool, error) { return tryOCRConfig(configPath, opts) }},
		{"OCR environment", func() (ResolvedEndpoint, bool, error) { return tryOCREnv(opts.Model) }},
		{"Claude Code environment", func() (ResolvedEndpoint, bool, error) { return tryCCEnv(opts.Model) }},
		{"Shell rc file", func() (ResolvedEndpoint, bool, error) { return tryShellRC(opts.Model) }},
	}

	for _, strategy := range strategies {
		ep, ok, err := strategy.fn()
		if err != nil {
			return ResolvedEndpoint{}, fmt.Errorf("resolve %s: %w", strategy.name, err)

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Create ~/.opencodereview/config.json and add the provider under the section named in the error
  2. If it is a built-in preset, put it under "providers"; if custom, under "custom_providers"
  3. Check the provider name spelling matches the key in the config file
  4. Drop the explicit provider so the resolver falls back to env/shell-rc strategies

Example fix

// before (no config file, custom provider "acme")
ocr review --provider acme
// after: ~/.opencodereview/config.json
{"custom_providers": {"acme": {"url": "https://api.acme.com", "api_key": "...", "model": "...", "protocol": "openai"}}}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := os.Stat(cfgPath); os.IsNotExist(err) {
    return fmt.Errorf("config %s missing; create it before using --provider", cfgPath)
}

Try / catch

_, err := llm.ResolveEndpointWithOptions(path, llm.ResolveOptions{Provider: name})
if err != nil && strings.Contains(err.Error(), "does not exist") {
    return fmt.Errorf("add provider %q to the config file first", name)
}

Prevention

When it happens

Trigger: Calling ResolveEndpointWithOptions with ResolveOptions.Provider set while ~/.opencodereview/config.json does not exist, or lacks the provider in the section matching its preset status (built-in preset -> "providers", custom -> "custom_providers").

Common situations: Passing --provider mycustomvendor on a fresh machine with no config file; putting a custom provider under "providers" instead of "custom_providers" (or vice versa); typo in the provider key so LookupProvider misses and it is looked up in custom_providers where it also is absent.

Related errors


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