prolic / HumusAmqp

PHP 7.4 AMQP library
https://humusamqp.readthedocs.io/
MIT License
76 stars 17 forks source link

Type issue with exceptions #98

Closed func0der closed 3 years ago

func0der commented 3 years ago

Hey mate,

I found a type problem in the exception handling.

Your are catching \Throwable here: https://github.com/prolic/HumusAmqp/blob/master/src/Driver/PhpAmqpLib/Queue.php#L193-L195

But AmqpException::fromPhpAmqpLib() can only handle \Exception: https://github.com/prolic/HumusAmqp/blob/master/src/Exception/AmqpException.php#L34

If there was an error like this Call to undefined method PhpAmqpLib\Channel\AMQPChannel::is_consuming() which just occurred in my code, PHP would fataly crash with:

TypeError: Argument 1 passed to Humus\Amqp\Exception\AmqpException::fromPhpAmqpLib() must be an instance of Exception, instance of Error given, called in vendor/prolic/humus-amqp/src/Driver/PhpAmqpLib/Queue.php on line 194 and defined in vendor/prolic/humus-amqp/src/Exception/AmqpException.php:34 Totally unrelated, just an example how I found it.

Such errors are easily spotted with static code analyses like PhpStan oder Psalm. :)

I am of to debug the unrelated problem above. flys away :D

prolic commented 3 years ago

Thanks man, you're the first who encountered this issue. Can you add a failing test case to the suite?

On Thu, Apr 8, 2021, 13:47 Lars @.***> wrote:

Hey mate,

I found a type problem in the exception handling.

Your are catching \Throwable here: https://github.com/prolic/HumusAmqp/blob/master/src/Driver/PhpAmqpLib/Queue.php#L193-L195

But AmqpException::fromPhpAmqpLib() can only handle \Exception: https://github.com/prolic/HumusAmqp/blob/master/src/Exception/AmqpException.php#L34

If there was an error like this Call to undefined method PhpAmqpLib\Channel\AMQPChannel::is_consuming() which just occurred in my code, PHP would fataly crash with:

TypeError: Argument 1 passed to Humus\Amqp\Exception\AmqpException::fromPhpAmqpLib() must be an instance of Exception, instance of Error given, called in vendor/prolic/humus-amqp/src/Driver/PhpAmqpLib/Queue.php on line 194 and defined in vendor/prolic/humus-amqp/src/Exception/AmqpException.php:34 Totally unrelated, just an example how I found it.

Such errors are easily spotted with static code analyses like PhpStan oder Psalm. :)

I am of to debug the unrelated problem above. flys away :D

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/prolic/HumusAmqp/issues/98, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADAJPDNJLUWK4LG347GCVDTHXT4DANCNFSM42TLPFIQ .