diff --git a/pkg/enqueue/Consumption/QueueConsumer.php b/pkg/enqueue/Consumption/QueueConsumer.php index 58b8fa06c..30d438dcd 100644 --- a/pkg/enqueue/Consumption/QueueConsumer.php +++ b/pkg/enqueue/Consumption/QueueConsumer.php @@ -299,7 +299,7 @@ private function onEnd(ExtensionInterface $extension, int $startTime, ?int $exit } /** - * The logic is similar to one in Symfony's ExceptionListener::. + * The logic is similar to one in Symfony's ExceptionListener::onKernelException(). * * https://github.com/symfony/symfony/blob/cbe289517470eeea27162fd2d523eb29c95f775f/src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php#L77 */ @@ -317,18 +317,16 @@ private function onProcessorException(ExtensionInterface $extension, Consumer $c return $result; } catch (\Exception $e) { - $wrapper = $e; - while ($prev = $wrapper->getPrevious()) { + $prev = $e; + do { if ($exception === $wrapper = $prev) { throw $e; } - } + } while ($prev = $wrapper->getPrevious()); - if ($exception !== $wrapper) { - $prev = new \ReflectionProperty('Exception', 'previous'); - $prev->setAccessible(true); - $prev->setValue($wrapper, $exception); - } + $prev = new \ReflectionProperty($wrapper instanceof \Exception ? \Exception::class : \Error::class, 'previous'); + $prev->setAccessible(true); + $prev->setValue($wrapper, $exception); throw $e; }