{"record":{"id":"aa258da8c7330f6c","repo":"alibaba/open-code-review","slug":"invalid-json-for-llm-extra-body-w","errorCode":null,"errorMessage":"invalid JSON for llm.extra_body: %w","messagePattern":"invalid JSON for llm\\.extra_body: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/opencodereview/config_cmd.go","lineNumber":592,"sourceCode":"\t\tcfg.ensureTelemetry()\n\t\tcfg.Telemetry.Enabled = b\n\tcase \"telemetry.exporter\", \"telemetry.Exporter\":\n\t\tcfg.ensureTelemetry()\n\t\tcfg.Telemetry.Exporter = value\n\tcase \"telemetry.otlp_endpoint\", \"telemetry.OTLPEndpoint\":\n\t\tcfg.ensureTelemetry()\n\t\tcfg.Telemetry.OTLPEndpoint = value\n\tcase \"telemetry.content_logging\", \"telemetry.ContentLog\":\n\t\tb, err := strconv.ParseBool(value)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid boolean for telemetry.content_logging: %w\", err)\n\t\t}\n\t\tcfg.ensureTelemetry()\n\t\tcfg.Telemetry.ContentLog = b\n\tcase \"llm.extra_body\", \"llm.ExtraBody\":\n\t\tvar m map[string]any\n\t\tif err := json.Unmarshal([]byte(value), &m); err != nil {\n\t\t\treturn fmt.Errorf(\"invalid JSON for llm.extra_body: %w\", err)\n\t\t}\n\t\tcfg.Llm.ExtraBody = m\n\tcase \"llm.retry_codes\", \"llm.RetryCodes\":\n\t\tcodes, warnings, err := llm.ParseRetryCodes(value)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfor _, w := range warnings {\n\t\t\tfmt.Fprintf(os.Stderr, \"[ocr] WARNING: %s\\n\", w)\n\t\t}\n\t\tcfg.Llm.RetryCodes = codes\n\tdefault:\n\t\treturn fmt.Errorf(\"unknown config key: %s\\nSupported keys: %s\\nProvider fields: api_key, api_key_cmd, url, protocol, model, models, auth_header, extra_body, extra_headers, retry_codes, aws_region, aws_profile\\nProtocol values: anthropic, anthropic-bedrock, openai, openai-responses\\nMCP server fields: type, command, args, env, url, headers, tools, setup\", key, strings.Join(supportedConfigKeys, \", \"))\n\t}\n\treturn nil\n}\n\nfunc applyProviderField(providerName string, entry *ProviderEntry, field, key, value string) error {","sourceCodeStart":574,"sourceCodeEnd":610,"githubUrl":"https://github.com/alibaba/open-code-review/blob/5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f/cmd/opencodereview/config_cmd.go#L574-L610","documentation":"Fires when the value for `ocr config set llm.extra_body` is not valid JSON that unmarshals into a map[string]any. extra_body is merged into outgoing LLM request bodies, so it must be a JSON object; the setter parses it eagerly so malformed JSON (or JSON arrays/scalars) is rejected at set time instead of corrupting later API requests.","triggerScenarios":"`ocr config set llm.extra_body '<value>'` where the value is not a JSON object — single quotes inside, missing quotes around keys, a JSON array, or unquoted text.","commonSituations":"Shell quoting mangling the JSON (double quotes stripped); passing a list instead of an object; pasting JSON5/YAML with comments or trailing commas; using single-quoted shell strings with embedded double quotes incorrectly.","solutions":["Pass a valid JSON object: `ocr config set llm.extra_body '{\"temperature\":0.2}'`","Single-quote the JSON in bash so inner double quotes survive","Validate with `echo '<value>' | jq .` before setting","If you need an array or scalar body, it is not supported — the value must be an object"],"exampleFix":"// before\nocr config set llm.extra_body temperature=0.2\n// after\nocr config set llm.extra_body '{\"temperature\":0.2}'","handlingStrategy":"validation","validationCode":"var m map[string]any\nif err := json.Unmarshal([]byte(v), &m); err != nil {\n    return fmt.Errorf(\"llm.extra_body must be a JSON object: %v\", err)\n}\n_ = runConfigSet(\"llm.extra_body\", v)","typeGuard":null,"tryCatchPattern":"if err := runConfigSet(\"llm.extra_body\", v); err != nil {\n    if strings.Contains(err.Error(), \"invalid JSON for llm.extra_body\") {\n        fmt.Fprintf(os.Stderr, \"not a JSON object: %s — try: '{\\\"temperature\\\":0.2}'\\n\", v)\n    }\n}","preventionTips":["Always single-quote JSON in bash so double quotes survive","Validate with `jq .` before setting","The value must be an object ({}), not an array or scalar","Store complex bodies in a variable or file to avoid quoting bugs"],"tags":["config","json","cli"],"backgroundTag":"json-parse-error","analyzedSha":"5cf97d0d15cbd41b602513c4be3bfec3cee5bf7f","analyzedAt":"2026-09-02T02:08:09.116Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}