diff --git a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php index eff4d8614f109..a340b572cc430 100644 --- a/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php +++ b/src/Symfony/Component/Messenger/Tests/Transport/Serialization/SerializerTest.php @@ -21,6 +21,7 @@ use Symfony\Component\Messenger\Transport\Serialization\Serializer; use Symfony\Component\Serializer as SerializerComponent; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; +use Symfony\Component\Serializer\Serializer as SymfonySerializer; use Symfony\Component\Serializer\SerializerInterface as SerializerComponentInterface; class SerializerTest extends TestCase @@ -230,6 +231,36 @@ public function testDecodingStampFailedDeserialization() ], ]); } + + public function testDecodingFailedInCustomNormalizer() + { + $serializer = new Serializer( + new SymfonySerializer( + [ + new class() implements SerializerComponent\Normalizer\DenormalizerInterface { + public function denormalize($data, $type, string $format = null, array $context = []) + { + throw new \Exception('Error in custom denormalizer.'); + } + + public function supportsDenormalization($data, $type, string $format = null) + { + return true; + } + }, + ], + [new SerializerComponent\Encoder\JsonEncoder()] + ) + ); + + $this->expectException(MessageDecodingFailedException::class); + $this->expectExceptionMessage('Could not decode message: Error in custom denormalizer.'); + + $serializer->decode([ + 'body' => '{}', + 'headers' => ['type' => \stdClass::class], + ]); + } } class DummySymfonySerializerNonSendableStamp implements NonSendableStampInterface { diff --git a/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php b/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php index b5e93370027b6..ffb824ae9533c 100644 --- a/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php +++ b/src/Symfony/Component/Messenger/Transport/Serialization/Serializer.php @@ -19,7 +19,6 @@ use Symfony\Component\Messenger\Stamp\StampInterface; use Symfony\Component\Serializer\Encoder\JsonEncoder; use Symfony\Component\Serializer\Encoder\XmlEncoder; -use Symfony\Component\Serializer\Exception\ExceptionInterface; use Symfony\Component\Serializer\Normalizer\ArrayDenormalizer; use Symfony\Component\Serializer\Normalizer\ObjectNormalizer; use Symfony\Component\Serializer\Serializer as SymfonySerializer; @@ -79,7 +78,7 @@ public function decode(array $encodedEnvelope): Envelope try { $message = $this->serializer->deserialize($encodedEnvelope['body'], $encodedEnvelope['headers']['type'], $this->format, $context); - } catch (ExceptionInterface $e) { + } catch (\Throwable $e) { throw new MessageDecodingFailedException('Could not decode message: '.$e->getMessage(), $e->getCode(), $e); } @@ -117,7 +116,7 @@ private function decodeStamps(array $encodedEnvelope): array try { $stamps[] = $this->serializer->deserialize($value, substr($name, \strlen(self::STAMP_HEADER_PREFIX)).'[]', $this->format, $this->context); - } catch (ExceptionInterface $e) { + } catch (\Throwable $e) { throw new MessageDecodingFailedException('Could not decode stamp: '.$e->getMessage(), $e->getCode(), $e); } }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: