ssut / nestjs-sqs

A project to make SQS easier to use within NestJS, with decorator-based handling and seamless NestJS-way integration.
MIT License
215 stars 53 forks source link

Thrown error inside batch message handler kills app. #29

Open cberiganTAG opened 2 years ago

cberiganTAG commented 2 years ago

Whenever an error is thrown inside a batch message handler and there is no error event handler method, an uncaught exception is thrown and kills the app.

Steps to reproduce:

  1. Set up handler like so:
@SqsMessageHandler('test', true)
public async handleMessage(messages: SQS.Message[]): Promise<void> {
  throw new Error('test')
}
  1. Do NOT include @SqsConsumerEventHandler('test', 'error').

It seems like when I include the error event handler, the error is able to be caught and logged. The app continues to run.

Expectation:

The error event handler should be an opt-in feature. The app should continue to function if individual handlers fail for whatever reason.

Results:

Throws uncaught exception

[1656014764276] ERROR: Error: Unexpected message handler failure: test
    at RentlyWebhookSqsHandler.handleMessage (C:\SourceControl\GITHUB\everest\backend\src\rently\sqs-handlers\rently-webhook-sqs-handler.service.ts:27:11)
    at Consumer.executeBatchHandler (C:\SourceControl\GITHUB\everest\backend\node_modules\@ssut\nestjs-sqs\node_modules\sqs-consumer\dist\consumer.js:303:24)
    at Consumer.processMessageBatch (C:\SourceControl\GITHUB\everest\backend\node_modules\@ssut\nestjs-sqs\node_modules\sqs-consumer\dist\consumer.js:267:24)
    at Consumer.handleSqsResponse (C:\SourceControl\GITHUB\everest\backend\node_modules\@ssut\nestjs-sqs\node_modules\sqs-consumer\dist\consumer.js:113:32)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Also terminates the app.

cberiganTAG commented 2 years ago

I think the necessary fix would be to have a default error listener on all consumers if one is not provided OR the sqs-consumer package should be emitting processing_error instead of error on batch message handlers throw errors.

n05la3 commented 1 year ago

This issue is related to #9

PetrShchukin commented 5 months ago

The issue is not with @ssut/nestjs-sqs. I am getting the same error using sqs-consumer package