Skip to content

Fix SQS MessageInterceptor exceptions handling#1600

Merged
tomazfernandes merged 1 commit intoawspring:mainfrom
tomazfernandes:GH-1595
Apr 5, 2026
Merged

Fix SQS MessageInterceptor exceptions handling#1600
tomazfernandes merged 1 commit intoawspring:mainfrom
tomazfernandes:GH-1595

Conversation

@tomazfernandes
Copy link
Copy Markdown
Contributor

Why

Closes #1595

When a MessageInterceptor throws an exception, the MessageListenerExecutionStage is never reached, so the exception never gets wrapped in ListenerExecutionFailedException. All downstream pipeline stages (ErrorHandler, after-processing interceptors, AcknowledgementHandler) expect to unwrap a message from the exception chain and fail with IllegalArgumentException: No ListenerExecutionFailedException found to unwrap messages.

This breaks valid use cases like interceptor-based idempotency checks that rely on the ErrorHandler to gracefully handle rejection.

What

  • Introduce MessageProcessingException interface as a common marker for exceptions that carry message references through the processing pipeline
  • Add InterceptorExecutionFailedException for failures in before-processing interceptors
  • ListenerExecutionFailedException now implements MessageProcessingException; static utility methods deprecated in favour of MessageProcessingException equivalents

How

  • Wrap interceptor exceptions in InterceptorExecutionFailedException via exceptionallyCompose in AbstractBeforeProcessingInterceptorExecutionStage (both single and batch paths)
  • Update all downstream stages (ErrorHandlerExecutionStage, AbstractAfterProcessingInterceptorExecutionStage, AcknowledgementHandlerExecutionStage) to use MessageProcessingException for unwrapping
  • Update observation adapter in AsyncComponentAdapters to preserve exception type when re-wrapping with updated message headers

Acceptance Criteria

  • Interceptor exceptions wrapped in InterceptorExecutionFailedException with message reference
  • ErrorHandler.handle() invoked for interceptor failures (single and batch)
  • After-processing interceptors called on interceptor failure
  • AcknowledgementHandler works correctly for interceptor failures
  • Both blocking and async interceptor paths covered
  • Observation adapter preserves exception type when re-wrapping
  • No regression in existing tests
  • Pipeline composition order unchanged

Testing

  • Updated unit tests in BeforeProcessingInterceptorExecutionStageTests and BeforeProcessingContextInterceptorExecutionStageTests to assert InterceptorExecutionFailedException with correct message references
  • Added integration tests verifying ErrorHandler and afterProcessing interceptor invocation when an interceptor throws (single and batch paths)
  • Added integration test verifying end-to-end recovery: interceptor throws → error handler swallows → message acknowledged → listener never called

@github-actions github-actions bot added the component: sqs SQS integration related issue label Apr 5, 2026
@tomazfernandes
Copy link
Copy Markdown
Contributor Author

CI tests failing due to #1586

Tests pass locally:
image

@tomazfernandes tomazfernandes merged commit b7aedb5 into awspring:main Apr 5, 2026
3 of 6 checks passed
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Exceptions are not handled when thrown in a SQS MessageInterceptor

1 participant