{"record":{"id":"6468d88044ac2627","repo":"alibaba/open-code-review","slug":"ocr-environment-w","errorCode":null,"errorMessage":"OCR environment: %w","messagePattern":"OCR environment: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/llm/resolver.go","lineNumber":263,"sourceCode":"\n// tryOCREnv reads OCR-specific environment variables.\nfunc tryOCREnv(modelOverride string) (ResolvedEndpoint, bool, error) {\n\turl := os.Getenv(envOCRLLMURL)\n\ttoken := os.Getenv(envOCRLLMToken)\n\tmodel := os.Getenv(envOCRLLMModel)\n\tif modelOverride != \"\" {\n\t\tmodel = modelOverride\n\t}\n\tif url == \"\" || token == \"\" || model == \"\" {\n\t\treturn ResolvedEndpoint{}, false, nil\n\t}\n\n\t// OCR_LLM_PROTOCOL (normalized) wins over OCR_USE_ANTHROPIC when set.\n\tprotocol := \"\"\n\tif raw := strings.TrimSpace(os.Getenv(envOCRLLMProtocol)); raw != \"\" {\n\t\tprotocol = NormalizeProtocol(raw)\n\t\tif err := ValidateProtocol(protocol); err != nil {\n\t\t\treturn ResolvedEndpoint{}, false, fmt.Errorf(\"OCR environment: %w\", err)\n\t\t}\n\t\tif protocol == ProtocolAnthropicBedrock {\n\t\t\treturn ResolvedEndpoint{}, false, fmt.Errorf(\"OCR environment: %w\", errBedrockNotConfigurable(envOCRLLMProtocol))\n\t\t}\n\t}\n\tif protocol == \"\" {\n\t\tuseAnthropic := true // default true\n\t\tif v := os.Getenv(envOCRUseAnthropic); v != \"\" {\n\t\t\tlower := strings.ToLower(v)\n\t\t\tuseAnthropic = lower == \"true\" || lower == \"1\" || lower == \"yes\"\n\t\t}\n\t\tif useAnthropic {\n\t\t\tprotocol = ProtocolAnthropic\n\t\t} else {\n\t\t\tprotocol = ProtocolOpenAIChatCompletions\n\t\t}\n\t}\n","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/internal/llm/resolver.go#L245-L281","documentation":"This is a wrapper error from tryOCREnv prefixed \"OCR environment:\"; the wrapped cause comes from ValidateProtocol rejecting the normalized OCR_LLM_PROTOCOL value. The OCR env strategy (OCR_LLM_URL + OCR_LLM_TOKEN + OCR_LLM_MODEL all set) activates protocol validation, and an unrecognized protocol aborts endpoint resolution instead of being silently coerced to a default.","triggerScenarios":"OCR_LLM_URL, OCR_LLM_TOKEN and OCR_LLM_MODEL are all set, and OCR_LLM_PROTOCOL holds a value that NormalizeProtocol cannot map to a known protocol (e.g. \"openai-chat-completions\", \"Anthropic Claude\", \"gpt4\").","commonSituations":"Typo in the protocol name, copied a vendor-specific protocol string from another tool's docs, or used a protocol alias supported by a different CLI but not by ocr.","solutions":["Set OCR_LLM_PROTOCOL to one of the valid values: anthropic, openai, openai-responses, or anthropic-bedrock (bedrock only via provider config)","Unset OCR_LLM_PROTOCOL entirely and rely on OCR_USE_ANTHROPIC=true|false to pick anthropic or openai-chat-completions","Check for stray whitespace/casing issues; the value is trimmed and normalized but must still match a known protocol name"],"exampleFix":"// before\nexport OCR_LLM_PROTOCOL=openai-chat\n\n// after\nexport OCR_LLM_PROTOCOL=openai  # or: openai-responses / anthropic","handlingStrategy":"validation","validationCode":"var valid = map[string]bool{\"anthropic\": true, \"openai\": true, \"openai-responses\": true, \"anthropic-bedrock\": true}\nif p := strings.TrimSpace(os.Getenv(\"OCR_LLM_PROTOCOL\")); p != \"\" && !valid[p] {\n    return fmt.Errorf(\"OCR_LLM_PROTOCOL %q is not one of anthropic|openai|openai-responses|anthropic-bedrock\", p)\n}","typeGuard":null,"tryCatchPattern":"if err := resolveEndpoint(ctx); err != nil {\n    var pe *fs.PathError\n    if strings.Contains(err.Error(), \"OCR environment:\") {\n        log.Fatalf(\"fix OCR_* env vars: %v\", err)\n    }\n    return err\n}","preventionTips":["Keep a snippet of the four accepted protocol values in your shell profile comments","Prefer OCR_USE_ANTHROPIC=true|false over OCR_LLM_PROTOCOL when you only need the two defaults","Test env changes with a dry config check before running a full review"],"tags":["configuration","env-vars","protocol"],"backgroundTag":"invalid-protocol-value","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}