Skip to content

Expose error code on error response metadata - #987

Merged
arandito merged 2 commits into
developfrom
add-error-code-to-response-metadata
Nov 25, 2026
Merged

arandito merged 2 commits into
developfrom
add-error-code-to-response-metadata

Conversation

@arandito

@arandito arandito commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Note

The modeled waiters PR #991 is stacked on top of this since it requires the error code to be available in unmodeled errors for matching.

Description

Exposes the error code of service errors on CallError.response_metadata.error_code, for modeled and unmodeled errors.

  • smithy-core adds ErrorResponseMetadata, a ResponseMetadata subclass with an error_code field. CallError.response_metadata is now an ErrorResponseMetadata. Outputs keep a plain ResponseMetadata.
  • Protocols set the code in a new _finalize_error hook, which then classifies the error for retries. It uses the same code that retry classification already uses.
  • The pipeline merges the request IDs and status code into the error's existing metadata, so the code is kept. This allows us to calculate the code once and store in the metadata without needing to store in a context key to populate it in the existing extract_response_metadata hook.
  • Error stubs from both generators now declare ErrorResponseMetadata.
  • Query-compatible services report the awsQuery code from x-amzn-query-error, such as AWS.SimpleQueueService.NonExistentQueue. It keeps the codes of awsQuery services like SNS and STS stable if they migrate to JSON.

Why a subclass?

This ensures that normal outputs don't carry an empty error_code. It also allows us to separate error-specific metadata from general response metadata. Java v2, Kotlin, and Rust also keep the code in error metadata that only errors carry.

Why not a field on the error?

A CallError.error_code field would rename modeled members on 90 AWS error shapes. A code field would rename 257. Placing this on error metadata avoids escaping all these fields to accommodate unmodeled errors.

Is this breaking?

For the most part no. However, code that assigns a plain ResponseMetadata to CallError.response_metadata fails type checking since it is now typed as ErrorResponseMetadata. We don't do this and this scenario seems highly unlikely.

Testing

  • Added unit tests for the error code across all protocols, a pipeline test for the metadata merge, and end-to-end tests through the generated ec2query client.
  • make test-unit, make test-functional, and make build-java pass. The retry classification tests pass unchanged.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@arandito
arandito added this pull request to stack #992 November 25, 2026 11:54
@arandito
arandito marked this pull request as ready for review November 25, 2026 13:23
@arandito
arandito requested a review from a team as a code owner November 25, 2026 13:23
@pytest.mark.parametrize("case", _CASES)
def test_error_code_is_reported(case: _Case) -> None:
metadata = _error_metadata(case, case.body("SomeError"))
assert metadata.error_code == "SomeError"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you also add a case where the code has a namespace prefix aws.foo#SomeError or URI suffix especially for JSON?

stobrien89
stobrien89 previously approved these changes Nov 25, 2026
kuhe
kuhe previously approved these changes Nov 25, 2026
@arandito
arandito dismissed stale reviews from kuhe and stobrien89 via 52fb46d November 25, 2026 18:52
@arandito
arandito force-pushed the add-error-code-to-response-metadata branch from 52fb46d to e558361 Compare November 25, 2026 19:00
@arandito
arandito force-pushed the add-error-code-to-response-metadata branch from e558361 to 1752e53 Compare November 25, 2026 20:48
@stobrien89
stobrien89 requested a review from kuhe November 25, 2026 21:25
@arandito
arandito merged commit a552e00 into develop Nov 25, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants