Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,12 @@ private <T> CompletableFuture<SendResult.Batch<T>> wrapSendException(Collection<

private <T> CompletableFuture<SendResult.Batch<T>> handleFailedSendBatch(String endpoint,
SendResult.Batch<T> result) {
return CompletableFuture.failedFuture(new SendBatchOperationFailedException("", endpoint, result));
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"

.collect(Collectors.joining(", ")));
return CompletableFuture.failedFuture(new SendBatchOperationFailedException(errorMessage, endpoint, result));
}

private <T> Collection<S> convertMessagesToSend(Collection<Message<T>> messages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.mockito.Mockito.*;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.awspring.cloud.sqs.MessageHeaderUtils;
import io.awspring.cloud.sqs.QueueAttributesResolvingException;
import io.awspring.cloud.sqs.SqsAcknowledgementException;
import io.awspring.cloud.sqs.listener.QueueNotFoundStrategy;
Expand Down Expand Up @@ -555,6 +556,8 @@ void shouldThrowIfHasFailedMessagesInBatchByDefault() {
assertThatThrownBy(() -> template.sendMany(queue, messages))
.isInstanceOf(SendBatchOperationFailedException.class)
.isInstanceOfSatisfying(SendBatchOperationFailedException.class, ex -> {
assertThat(ex.getMessage()).contains(queue).contains(testErrorMessage)
.contains(MessageHeaderUtils.getRawMessageId(message2));
assertThat(ex.getFailedMessages().iterator().next().getPayload()).isEqualTo(payload2);
assertThat(ex.getEndpoint()).isEqualTo(queue);
SendResult.Batch<String> sendBatchResult = ex.getSendBatchResult(String.class);
Expand Down