translator: handle numeric OpenAI error.code in Anthropic→OpenAI error translation - #2161
Conversation
error.code in Anthropic→OpenAI error translation
|
@copilot fix the failing checks by setting a proper PR title and description according to the check requirements. |
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (70.37%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #2161 +/- ##
==========================================
- Coverage 84.73% 84.71% -0.02%
==========================================
Files 144 144
Lines 21134 21161 +27
==========================================
+ Hits 17908 17927 +19
- Misses 2145 2152 +7
- Partials 1081 1082 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
I checked the failing PR Style jobs: they require a Conventional Commit PR title and a PR description whose first line is exactly |
error.code in Anthropic→OpenAI error translationerror.code in Anthropic→OpenAI error translation
|
/retest |
…ror translation (envoyproxy#2161) **Description** Anthropic→OpenAI error translation could fail with an internal 500 when an OpenAI-compatible upstream returned a structured JSON error where `error.code` was numeric (e.g. `400`) instead of string. This change makes the error model tolerant to both representations so upstream 4xx diagnostics can still be translated and surfaced to Anthropic clients. - **Schema decoding hardening (`internal/apischema/openai/openai.go`)** - Added `UnmarshalJSON` for `openai.ErrorType`. - `error.code` now accepts: - JSON string (`"code":"400"`) - JSON number (`"code":400`) - `null` / omitted - Numeric values are normalized to the existing internal `*string` field. - **Translator regression coverage (`internal/translator/anthropic_openai_test.go`)** - Extended `TestAnthropicToOpenAITranslator_ResponseError` with a JSON error fixture containing numeric `code`. - Confirms response still maps to Anthropic error envelope with expected `type` and `message`. ```json { "type": "error", "error": { "type": "invalid_request_error", "message": "Bad request", "param": null, "code": 400 } } ``` **Related Issues/PRs (if applicable)** Fixes envoyproxy#2151 **Special notes for reviewers (if applicable)** N/A --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Ignasi Barrera <ignasi@tetrate.io> Signed-off-by: yxia216 <yxia216@bloomberg.net>
…ror translation (envoyproxy#2161) **Description** Anthropic→OpenAI error translation could fail with an internal 500 when an OpenAI-compatible upstream returned a structured JSON error where `error.code` was numeric (e.g. `400`) instead of string. This change makes the error model tolerant to both representations so upstream 4xx diagnostics can still be translated and surfaced to Anthropic clients. - **Schema decoding hardening (`internal/apischema/openai/openai.go`)** - Added `UnmarshalJSON` for `openai.ErrorType`. - `error.code` now accepts: - JSON string (`"code":"400"`) - JSON number (`"code":400`) - `null` / omitted - Numeric values are normalized to the existing internal `*string` field. - **Translator regression coverage (`internal/translator/anthropic_openai_test.go`)** - Extended `TestAnthropicToOpenAITranslator_ResponseError` with a JSON error fixture containing numeric `code`. - Confirms response still maps to Anthropic error envelope with expected `type` and `message`. ```json { "type": "error", "error": { "type": "invalid_request_error", "message": "Bad request", "param": null, "code": 400 } } ``` **Related Issues/PRs (if applicable)** Fixes envoyproxy#2151 **Special notes for reviewers (if applicable)** N/A --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Ignasi Barrera <ignasi@tetrate.io> Signed-off-by: yxia216 <yxia216@bloomberg.net>
Description
Anthropic→OpenAI error translation could fail with an internal 500 when an OpenAI-compatible upstream returned a structured JSON error where
error.codewas numeric (e.g.400) instead of string. This change makes the error model tolerant to both representations so upstream 4xx diagnostics can still be translated and surfaced to Anthropic clients.Schema decoding hardening (
internal/apischema/openai/openai.go)UnmarshalJSONforopenai.ErrorType.error.codenow accepts:"code":"400")"code":400)null/ omitted*stringfield.Translator regression coverage (
internal/translator/anthropic_openai_test.go)TestAnthropicToOpenAITranslator_ResponseErrorwith a JSON error fixture containing numericcode.typeandmessage.{ "type": "error", "error": { "type": "invalid_request_error", "message": "Bad request", "param": null, "code": 400 } }Related Issues/PRs (if applicable)
Fixes #2151
Special notes for reviewers (if applicable)
N/A