From 89b4d24d26bf840f6cd66f709c000ab431f90dfe Mon Sep 17 00:00:00 2001 From: Patrick Mac Gregor Date: Mon, 9 Nov 2020 13:27:32 +0100 Subject: [PATCH] [fix] queue consumption: catch throwable for processing errors cf. issue #1113 --- Consumption/Context/ProcessorException.php | 6 +++--- Consumption/QueueConsumer.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Consumption/Context/ProcessorException.php b/Consumption/Context/ProcessorException.php index f41f232..329b13d 100644 --- a/Consumption/Context/ProcessorException.php +++ b/Consumption/Context/ProcessorException.php @@ -26,7 +26,7 @@ final class ProcessorException private $message; /** - * @var \Exception + * @var \Throwable */ private $exception; @@ -44,7 +44,7 @@ final class ProcessorException */ private $logger; - public function __construct(Context $context, Consumer $consumer, Message $message, \Exception $exception, int $receivedAt, LoggerInterface $logger) + public function __construct(Context $context, Consumer $consumer, Message $message, \Throwable $exception, int $receivedAt, LoggerInterface $logger) { $this->context = $context; $this->consumer = $consumer; @@ -69,7 +69,7 @@ public function getMessage(): Message return $this->message; } - public function getException(): \Exception + public function getException(): \Throwable { return $this->exception; } diff --git a/Consumption/QueueConsumer.php b/Consumption/QueueConsumer.php index 6cb9029..80936bf 100644 --- a/Consumption/QueueConsumer.php +++ b/Consumption/QueueConsumer.php @@ -195,7 +195,7 @@ public function consume(ExtensionInterface $runtimeExtension = null): void if (null === $result) { try { $result = $processor->process($message, $this->interopContext); - } catch (\Exception $e) { + } catch (\Exception | \Throwable $e) { $result = $this->onProcessorException($extension, $consumer, $message, $e, $receivedAt); } } @@ -303,7 +303,7 @@ private function onEnd(ExtensionInterface $extension, int $startTime, ?int $exit * * https://github.com/symfony/symfony/blob/cbe289517470eeea27162fd2d523eb29c95f775f/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php#L77 */ - private function onProcessorException(ExtensionInterface $extension, Consumer $consumer, Message $message, \Exception $exception, int $receivedAt) + private function onProcessorException(ExtensionInterface $extension, Consumer $consumer, Message $message, \Throwable $exception, int $receivedAt) { $processorException = new ProcessorException($this->interopContext, $consumer, $message, $exception, $receivedAt, $this->logger);