Repository navigation
fix: add typed GAOS 4XX/5XX error responses and surface backend error messages in Java, Go, and CLI - #3310
Open
copybara-service[bot] wants to merge 1 commit into
Open
fix: add typed GAOS 4XX/5XX error responses and surface backend error messages in Java, Go, and CLI#3310copybara-service[bot] wants to merge 1 commit into
copybara-service[bot] wants to merge 1 commit into
Conversation
… messages in Java, Go, and CLI
Operations outside the core `/interactions` CRUD paths omitted `4XX` and `5XX` response mappings in the GAOS OpenAPI spec, causing generated SDKs to fall back to untyped generic errors; additionally, Speakeasy-generated Java, Go, and CLI error classes pass the placeholder `"API error occurred"` when error details are nested under `{error: {message}}`.
1. **GAOS `4XX`/`5XX` error response overlay (`overlays/gaos/15-error-responses.yaml`)**:
- Defines shared `ApiError` (`ApiErrorCode`: `integer | string`, `message`: `string` with `x-speakeasy-error-message: true`, `ApiErrorStatus`: `string | integer`, `details`: `array` of `object`), `ApiClientError` (`4XX`), and `ApiServerError` (`5XX`) schemas, accepting both standard OnePlatform HTTP error envelopes (`code: int`, `status: str`, `details: [...]`) and Interactions HTTP error envelopes (`code: str`) without colliding with the SSE `#/components/schemas/Error` schema.
- Applies `4XX` -> `ApiClientError` and `5XX` -> `ApiServerError` to all GAOS operations that lack `4XX` responses (32 public operations and 47 internal operations, including `POST /{api_version}/decisions`, `/feedback`, `/agents/{id}/triggers`, and `/interactions/{id}/auth_tokens`).
- Bridges non-interaction Java and .NET operations onto native `ClientException`/`ServerException` (`ClientError`/`ServerError`) and surfaces typed `error.message` directly in Python, TypeScript, Go (`apierrors.ApiClientError` / `ApiServerError`), and CLI (`sdkerrors.ApiClientError` / `ApiServerError`).
2. **Backend error message surfacing in Java, Go, and CLI**:
- **Java**: Emits package-private `GaosErrorBody` (`scripts/templates/error_body.java.tmpl`) and forwards `GaosErrorBody.status(body)` (OnePlatform `error.status`, else Interactions string `error.code`, else `""`) and `GaosErrorBody.message(message, body)` to `com.google.genai.errors.ApiException` from `GaosBaseException`, `GaosClientException`, and `GaosServerException` when Speakeasy passes `"API error occurred"`.
- **Go**: Emits `messageFromBody` (`scripts/templates/error_body.go.tmpl`) in `interactions/models/apierrors/errorbody.go` and calls it from `NewAPIError` on fallback responses.
- **CLI**: Emits `messageFromBody` in `internal/sdk/models/sdkerrors/errorbody.go` and calls it from `NewSDKDefaultError` (covering fallback responses, `classic.openapi.json` operations, and `rawhttp.go`).
3. **Sync hardening & tests**:
- Switches Java error reparent replacements in `sync_speakeasy_outputs.py` (`reparent_java_error`) to `_replace_once` so generator template changes fail loudly at sync time, and adds `patch_go_apierrors` and `patch_cli_sdkerrors`.
- Regenerates OAD goldens and all 6 SDKs + CLI, and adds/updates error compatibility and unit tests across Java, .NET, Go, CLI, and `sync_speakeasy_outputs_test.py`.
FUTURE_COPYBARA_INTEGRATE_REVIEW=#3249 from googleapis:release-please--branches--main 4b4b0f3
PiperOrigin-RevId: 1015698193
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: add typed GAOS 4XX/5XX error responses and surface backend error messages in Java, Go, and CLI
Operations outside the core
/interactionsCRUD paths omitted4XXand5XXresponse mappings in the GAOS OpenAPI spec, causing generated SDKs to fall back to untyped generic errors; additionally, Speakeasy-generated Java, Go, and CLI error classes pass the placeholder"API error occurred"when error details are nested under{error: {message}}.GAOS
4XX/5XXerror response overlay (overlays/gaos/15-error-responses.yaml):ApiError(ApiErrorCode:integer | string,message:stringwithx-speakeasy-error-message: true,ApiErrorStatus:string | integer,details:arrayofobject),ApiClientError(4XX), andApiServerError(5XX) schemas, accepting both standard OnePlatform HTTP error envelopes (code: int,status: str,details: [...]) and Interactions HTTP error envelopes (code: str) without colliding with the SSE#/components/schemas/Errorschema.4XX->ApiClientErrorand5XX->ApiServerErrorto all GAOS operations that lack4XXresponses (32 public operations and 47 internal operations, includingPOST /{api_version}/decisions,/feedback,/agents/{id}/triggers, and/interactions/{id}/auth_tokens).ClientException/ServerException(ClientError/ServerError) and surfaces typederror.messagedirectly in Python, TypeScript, Go (apierrors.ApiClientError/ApiServerError), and CLI (sdkerrors.ApiClientError/ApiServerError).Backend error message surfacing in Java, Go, and CLI:
GaosErrorBody(scripts/templates/error_body.java.tmpl) and forwardsGaosErrorBody.status(body)(OnePlatformerror.status, else Interactions stringerror.code, else"") andGaosErrorBody.message(message, body)tocom.google.genai.errors.ApiExceptionfromGaosBaseException,GaosClientException, andGaosServerExceptionwhen Speakeasy passes"API error occurred".messageFromBody(scripts/templates/error_body.go.tmpl) ininteractions/models/apierrors/errorbody.goand calls it fromNewAPIErroron fallback responses.messageFromBodyininternal/sdk/models/sdkerrors/errorbody.goand calls it fromNewSDKDefaultError(covering fallback responses,classic.openapi.jsonoperations, andrawhttp.go).Sync hardening & tests:
sync_speakeasy_outputs.py(reparent_java_error) to_replace_onceso generator template changes fail loudly at sync time, and addspatch_go_apierrorsandpatch_cli_sdkerrors.sync_speakeasy_outputs_test.py.FUTURE_COPYBARA_INTEGRATE_REVIEW=#3249 from googleapis:release-please--branches--main 4b4b0f3