Skip to content

fix(core): handle empty error response body in AwsQuery protocol deserialization#7766

Merged
kuhe merged 1 commit intoaws:mainfrom
TrevorBurnham:fix/sqs-deserialization-empty-error-body
Feb 23, 2026
Merged

fix(core): handle empty error response body in AwsQuery protocol deserialization#7766
kuhe merged 1 commit intoaws:mainfrom
TrevorBurnham:fix/sqs-deserialization-empty-error-body

Conversation

@TrevorBurnham
Copy link
Contributor

fix(core): handle empty error response body in AwsQuery protocol deserialization

Fixes #7749

Problem

When an AWS Query protocol service (e.g. SQS) returns an HTTP 500 with an empty or malformed XML body, the SDK throws a raw TypeError: Cannot set properties of undefined instead of a proper ServiceException.

The root cause is in AwsQueryProtocol.handleError(): loadQueryError(dataObject) returns undefined when the parsed body has no Error, Errors, or Errors[0].Error fields. The code then immediately tries to set errorData.message = message on the undefined value, crashing before the error can be properly constructed.

This also affects EC2 Query protocol clients since AwsEc2QueryProtocol inherits handleError from AwsQueryProtocol.

Solution

Default the return value of loadQueryError() to an empty object (?? {}) so that property assignment and access on errorData succeeds even when the response body is empty. The error is then constructed normally with Type: undefined, Code: undefined, and Message: "Unknown".

Changes

  • packages-internal/core/src/submodules/protocols/query/AwsQueryProtocol.ts — add ?? {} fallback for loadQueryError() result
  • packages-internal/core/src/submodules/protocols/query/AwsQueryProtocol.spec.ts — add test for empty error response body

@TrevorBurnham TrevorBurnham requested a review from a team as a code owner February 22, 2026 18:13
…rialization

When an AWS Query service (e.g. SQS) returns an HTTP 500 with an empty
or malformed body, loadQueryError() returns undefined. The handleError
method then crashes with "Cannot set properties of undefined" when
trying to set errorData.message, which surfaces to users as a
TypeError instead of a proper ServiceException.

Default loadQueryError() result to an empty object so that error
metadata is still populated correctly.

Fixes aws#7749
@kuhe kuhe force-pushed the fix/sqs-deserialization-empty-error-body branch from e1a08fc to 36eed1d Compare February 23, 2026 00:56
@kuhe kuhe mentioned this pull request Feb 23, 2026
@kuhe kuhe merged commit 7d97314 into aws:main Feb 23, 2026
9 of 10 checks passed
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 10, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SQS Deserialization Error: Cannot read properties of undefined (reading 'Type')

2 participants