Skip to content

fix: add descriptive error message to SendBatchOperationFailedException - #1624

Open
Baqirrizvidev wants to merge 1 commit into
awspring:mainfrom
Baqirrizvidev:fix/sqs-batch-failure-exception-message
Open

fix: add descriptive error message to SendBatchOperationFailedException#1624
Baqirrizvidev wants to merge 1 commit into
awspring:mainfrom
Baqirrizvidev:fix/sqs-batch-failure-exception-message

Conversation

@Baqirrizvidev

Copy link
Copy Markdown
Contributor

This PR addresses Issue #1605 by constructing a detailed, descriptive exception message when creating a SendBatchOperationFailedException.

Problem

Previously, in AbstractMessagingTemplate.handleFailedSendBatch, a SendBatchOperationFailedException was created with a hardcoded empty string "" as the exception message. As a result, e.getMessage() returned "", rendering the exception silent in logs and requiring developers to manually extract details via e.getSendBatchResult().failed().

Solution

This PR updates AbstractMessagingTemplate to dynamically construct a diagnostic error message when a batch send operation fails. The message now contains:

  • The target SQS queue/endpoint.
  • The raw SQS message ID (or Spring message ID) of each failed message in the batch.
  • The associated failure error message returned from the SQS client.

Testing

  • Added assertions to the existing shouldThrowIfHasFailedMessagesInBatchByDefault unit test in SqsTemplateTests to verify that SendBatchOperationFailedException contains a message with the expected queue name, failed message ID, and SQS error details.
  • Verified that all unit tests pass successfully.

@github-actions github-actions Bot added the component: sqs SQS integration related issue label May 23, 2026

@tomazfernandes tomazfernandes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@Baqirrizvidev thanks for the PR.

Left a comment for a null guard to be on the safe side. We're changing correlation in a few places. Should be good to merge with that change.

String errorMessage = "Send batch operation failed for endpoint %s. Failed messages: %s.".formatted(endpoint,
result.failed().stream()
.map(failed -> "[Message ID: %s, Error: %s]"
.formatted(MessageHeaderUtils.getRawMessageId(failed.message()), failed.errorMessage()))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add a small guard against null here in case correlation fails in a previous step and the message is not included in the batch:

E.g.:

failed.message() != null ? MessageHeaderUtils.getRawMessageId(failed.message())                                                                                                                                                                                   
                                                                        : "unknown"

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

Labels

component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants