From 0375baa72c08fa74e1cfcf38cb59de4fd6fe0ee7 Mon Sep 17 00:00:00 2001 From: Patrick Mac Gregor Date: Mon, 9 Nov 2020 13:40:09 +0100 Subject: [PATCH] [fix] queue consumption: catch throwable for processing errors cf. issue #1113 --- pkg/enqueue/Consumption/Context/ProcessorException.php | 6 +++--- pkg/enqueue/Consumption/QueueConsumer.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pkg/enqueue/Consumption/Context/ProcessorException.php b/pkg/enqueue/Consumption/Context/ProcessorException.php index f41f23271..329b13d93 100644 --- a/pkg/enqueue/Consumption/Context/ProcessorException.php +++ b/pkg/enqueue/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/pkg/enqueue/Consumption/QueueConsumer.php b/pkg/enqueue/Consumption/QueueConsumer.php index 6cb90290e..80936bf58 100644 --- a/pkg/enqueue/Consumption/QueueConsumer.php +++ b/pkg/enqueue/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);