alibaba/open-code-review · error

%s: %w

Error message

%s: %w

What it means

parseEnvOverrides runs before any resolution strategy and parses OCR_LLM_EXTRA_HEADERS with ParseExtraHeaders. If the raw string is not a valid header list, the error is wrapped as "OCR_LLM_EXTRA_HEADERS: %w" and aborts resolution up front — deliberately before any credential prompt (api_key_cmd) can run, so a typo cannot waste an interactive authentication.

Source

Thrown at internal/llm/resolver.go:171

// strategy resolves the endpoint. Parsed once, up front — see the call site in
// ResolveEndpointWithOptions for why the timing matters.
type envOverrides struct {
	timeout    time.Duration
	hasTimeout bool
	headers    map[string]string
}

func parseEnvOverrides() (envOverrides, error) {
	var env envOverrides
	var err error
	env.timeout, env.hasTimeout, err = parseTimeoutEnv()
	if err != nil {
		return envOverrides{}, err
	}
	if raw := os.Getenv(envOCRLLMExtraHeaders); raw != "" {
		env.headers, err = ParseExtraHeaders(raw)
		if err != nil {
			return envOverrides{}, fmt.Errorf("%s: %w", envOCRLLMExtraHeaders, err)
		}
	}
	return env, nil
}

// finalizeResolvedEndpoint stamps the source label, strips the model suffix and
// applies the global env overrides, which win over config-file values.
func finalizeResolvedEndpoint(source string, ep ResolvedEndpoint, env envOverrides) ResolvedEndpoint {
	if ep.Source == "" {
		ep.Source = source
	}
	ep.Model = stripModelSuffix(ep.Model)
	if env.hasTimeout {
		ep.Timeout = env.timeout
	}
	if env.headers != nil {
		if ep.ExtraHeaders == nil {
			ep.ExtraHeaders = env.headers

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Fix the OCR_LLM_EXTRA_HEADERS format to match what ParseExtraHeaders expects (key/value pairs with the supported delimiters)
  2. Check shell quoting: quote the whole value (OCR_LLM_EXTRA_HEADERS='X-A: 1, X-B: 2')
  3. Unset the variable if extra headers are not needed

Example fix

// before
export OCR_LLM_EXTRA_HEADERS="X-Org"
// after
export OCR_LLM_EXTRA_HEADERS="X-Org: team1,X-Trace: on"
Defensive patterns

Strategy: validation

Validate before calling

raw := os.Getenv("OCR_LLM_EXTRA_HEADERS")
if raw != "" {
    if _, err := llm.ParseExtraHeaders(raw); err != nil {
        return fmt.Errorf("OCR_LLM_EXTRA_HEADERS invalid: %w", err)
    }
}

Try / catch

if err != nil && strings.Contains(err.Error(), "OCR_LLM_EXTRA_HEADERS") {
    return fmt.Errorf("check OCR_LLM_EXTRA_HEADERS format (key: value pairs): %w", err)
}

Prevention

When it happens

Trigger: OCR_LLM_EXTRA_HEADERS is set to a string ParseExtraHeaders cannot parse — e.g. wrong separator, missing key or value, or unescaped characters ("X-A=1;" or "X-A" instead of "X-A: 1,X-B: 2").

Common situations: Copying a header string from curl -H syntax without adapting the separator format; trailing separators; setting the variable in shell rc with quoting that strips or mangles the delimiters.

Related errors


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