alibaba/open-code-review · error
invalid extra headers for %s: %w
Error message
invalid extra headers for %s: %w
What it means
applyProviderField returns this when llm.ParseExtraHeaders rejects the value given for a provider's 'extra_headers' field. ParseExtraHeaders enforces the expected header format (e.g. key: value pairs), so anything malformed in that format fails here with the field name and underlying reason wrapped in.
Source
Thrown at cmd/opencodereview/config_cmd.go:662
return fmt.Errorf("invalid model list for %s: %w", key, err)
}
entry.Models = models
case "auth_header":
normalized, err := llm.NormalizeAuthHeader(value)
if err != nil {
return err
}
entry.AuthHeader = normalized
case "extra_body":
var m map[string]any
if err := json.Unmarshal([]byte(value), &m); err != nil {
return fmt.Errorf("invalid JSON for %s: %w", key, err)
}
entry.ExtraBody = m
case "extra_headers":
parsed, err := llm.ParseExtraHeaders(value)
if err != nil {
return fmt.Errorf("invalid extra headers for %s: %w", key, err)
}
entry.ExtraHeaders = parsed
case "retry_codes":
codes, warnings, err := llm.ParseRetryCodes(value)
if err != nil {
return fmt.Errorf("invalid retry codes for %s: %w", key, err)
}
for _, w := range warnings {
fmt.Fprintf(os.Stderr, "[ocr] WARNING: %s\n", w)
}
entry.RetryCodes = codes
case "aws_region", "aws_profile":
normalized, err := normalizeAWSSetting(field, key, value)
if err != nil {
return err
}
if !providerAcceptsAWSSettings(providerName, entry) {
return fmt.Errorf("%s does not apply to provider %q: aws_region and aws_profile are only used by providers that authenticate from the AWS credential chain (protocol %s)", field, providerName, llm.ProtocolAnthropicBedrock)View on GitHub (pinned to 5cf97d0d15)
Solutions
- Check the expected format used by llm.ParseExtraHeaders (Name: value pairs) and fix the value
- Single-quote the value and retry, e.g. ocr config set providers.foo.extra_headers 'X-Custom: abc'
- Test the header string with a small Go snippet or the parse function before storing it
Example fix
// before ocr config set providers.foo.extra_headers "Bearer abc123" // after ocr config set providers.foo.extra_headers "Authorization: Bearer abc123"
Defensive patterns
Strategy: validation
Validate before calling
h='X-Custom: abc' [[ "$h" == *": "* ]] || [[ "$h" == *:* ]] && ocr config set providers.foo.extra_headers "$h" || echo "header must be Name: value"
Try / catch
parsed, err := llm.ParseExtraHeaders(value)
if err != nil {
return fmt.Errorf("invalid extra headers: %w", err)
} Prevention
- Always use 'Header-Name: value' syntax
- Quote the whole header string in the shell
- Test with one header first, then add more
When it happens
Trigger: `ocr config set providers.<name>.extra_headers "Bearer token"` or any value not shaped like parseable headers (missing separator between header name and value, stray commas, empty pairs).
Common situations: Users paste an Authorization header value without the 'Name: value' syntax; shell expansion eats colons or quotes; using semicolons instead of commas/newlines between multiple headers.
Related errors
- load config: %w
- unset supports provider, max_tokens, effort, custom_provider
- MCP server %q not found
- custom provider %q not found
- read app config %s: %w
AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02).
Data as JSON: /api/errors/76bb2fb53553f631.
Report an issue: GitHub.