alibaba/open-code-review · error

custom provider %q not found

Error message

custom provider %q not found

What it means

deleteCustomProvider returns this error when cfg.CustomProviders is nil, meaning no customProviders section exists in the config. Called from unsetCustomProvider during 'ocr config unset provider <name>'; the deletion aborts before any mutation.

Source

Thrown at cmd/opencodereview/config_cmd.go:292

	delete(cfg.MCPServers, name)
	if len(cfg.MCPServers) == 0 {
		cfg.MCPServers = nil
	}

	if err := saveConfig(configPath, cfg); err != nil {
		return err
	}

	fmt.Printf("Deleted MCP server %q.\n", name)
	return nil
}

// deleteCustomProvider removes a custom provider from cfg in memory.
// Returns true if the deleted provider was the active one.
func deleteCustomProvider(cfg *Config, name string) (bool, error) {
	if cfg.CustomProviders == nil {
		return false, fmt.Errorf("custom provider %q not found", name)
	}
	if _, exists := cfg.CustomProviders[name]; !exists {
		return false, fmt.Errorf("custom provider %q not found", name)
	}

	wasActive := cfg.Provider == name
	delete(cfg.CustomProviders, name)
	if len(cfg.CustomProviders) == 0 {
		cfg.CustomProviders = nil
	}

	if wasActive {
		cfg.Provider = ""
		cfg.Model = ""
	}

	return wasActive, nil
}

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Verify the name refers to a custom provider you previously added with 'ocr config set provider <name> ...'.
  2. List existing custom providers in the config file before unsetting.
  3. If the goal is to disable provider-based config entirely, run 'ocr config unset provider' without a name instead.

Example fix

// before: no custom providers configured
$ ocr config unset provider openai
error: custom provider "openai" not found

// after: unset active provider instead
$ ocr config unset provider
Defensive patterns

Strategy: validation

Validate before calling

cfg, _ := LoadAppConfig(configPath)
if cfg == nil || cfg.CustomProviders == nil {
    return fmt.Errorf("no custom providers configured; nothing to unset")
}

Type guard

func hasCustomProviders(cfg *Config) bool {
    return cfg != nil && cfg.CustomProviders != nil
}

Try / catch

if err := unsetCustomProvider(configPath, name); err != nil && strings.Contains(err.Error(), "not found") {
    return nil // already absent
}

Prevention

When it happens

Trigger: Running 'ocr config unset provider <name>' on a config that has never defined any custom provider (no customProviders key in the JSON).

Common situations: Attempting to unset a built-in provider name (only custom providers are deletable) on a config without custom providers; fresh install; script assuming providers exist.

Related errors


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