alibaba/open-code-review · error

invalid provider key %q: expected providers.<name>.<field>

Error message

invalid provider key %q: expected providers.<name>.<field>

What it means

setProviderValue parses provider config keys with the rigid shape providers.<name>.<field>. If splitting the key on dots does not yield exactly three non-empty parts, the key does not address a provider field and this error is returned, telling the user the expected format.

Source

Thrown at cmd/opencodereview/config_cmd.go:792

}

// ensureModelInList appends model to the end when missing; never reorders existing entries.
func ensureModelInList(models []string, model string) []string {
	model = strings.TrimSpace(model)
	if model == "" {
		return models
	}
	if llm.ModelListContains(models, model) {
		return models
	}
	out := append([]string(nil), models...)
	return append(out, model)
}

func setProviderValue(cfg *Config, key, value string) error {
	parts := strings.SplitN(key, ".", 3)
	if len(parts) != 3 || parts[1] == "" || parts[2] == "" {
		return fmt.Errorf("invalid provider key %q: expected providers.<name>.<field>", key)
	}
	if _, isPreset := llm.LookupProvider(parts[1]); !isPreset {
		return setCustomProviderField(cfg, parts[1], parts[2], key, value)
	}
	if cfg.Providers == nil {
		cfg.Providers = make(map[string]ProviderEntry)
	}
	entry := cfg.Providers[parts[1]]
	if err := applyProviderField(parts[1], &entry, parts[2], key, value); err != nil {
		return err
	}
	cfg.Providers[parts[1]] = entry
	return nil
}

func setCustomProviderValue(cfg *Config, key, value string) error {
	parts := strings.SplitN(key, ".", 3)
	if len(parts) != 3 || parts[1] == "" || parts[2] == "" {

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Supply the full three-part key: ocr config set providers.<name>.<field> <value>
  2. Ensure the provider name and field are non-empty
  3. If setting a custom provider, use custom_providers.<name>.<field> instead

Example fix

// before
ocr config set providers.myprovider
// after
ocr config set providers.myprovider.protocol anthropic
Defensive patterns

Strategy: validation

Validate before calling

key="providers.myprovider.url"
count=$(awk -F. '{print NF}' <<< "$key")
[[ "$count" -eq 3 ]] || echo "key must be providers.<name>.<field>"

Try / catch

parts := strings.SplitN(key, ".", 3)
if len(parts) != 3 || parts[1] == "" || parts[2] == "" {
    return fmt.Errorf("invalid provider key %q: expected providers.<name>.<field>", key)
}

Prevention

When it happens

Trigger: `ocr config set providers <value>` (only two segments), `ocr config set providers.myprovider` (two segments), or `ocr config set providers..url x` / `ocr config set providers.myprovider. x` (empty name or field).

Common situations: Forgetting the field part of the key; shell interpolation producing an empty segment ($UNSET_VAR); applying key/value pairs from a script with missing fields.

Related errors


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