-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Symfony version(s) affected: 4.3
Description
Pdo throws exception with error code 'HY000', and Symfony Messenger component generates exception because of that in:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Messenger/Exception/HandlerFailedException.php#L32
Error(code: 0): Wrong parameters for Symfony\\Component\\Messenger\\Exception\\HandlerFailedException([string $message [, long $code [, Throwable $previous = NULL]]]) at /var/www/html/vendor/symfony/messenger/Exception/HandlerFailedException.php:29)
[stacktrace]
#0 /var/www/html/vendor/symfony/messenger/Exception/HandlerFailedException.php(29): Exception->__construct('SQLSTATE[HY000]...', 'HY000', Object(Doctrine\\DBAL\\Driver\\PDOException))
as described in: https://www.php.net/manual/en/exception.getcode.php
getCode could return mixed, which is not handled in code:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Messenger/Exception/HandlerFailedException.php#L32
and passed to constructor that requires int:
https://www.php.net/manual/en/exception.construct.php
How to reproduce
throw exception inside Messenger handler:
throw new \PDOException('test', 'HY000');
Possible Solution
cast it to int or set zero in case of string here:
https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Messenger/Exception/HandlerFailedException.php#L32