Skip to content

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
mainfrom
copybara/1015698193
Open

copybara-service[bot] wants to merge 1 commit into
mainfrom
copybara/1015698193

Conversation

@copybara-service

Copy link
Copy Markdown

fix: add typed GAOS 4XX/5XX error responses and surface backend error 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

… 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant