Skip to content

Messenger exception normalizer conflicts with other possible exception normalizers #40256

@goetas

Description

@goetas

Symfony version(s) affected: 5.2.3

Description
#32341 and #38941 started to serialize and unserialize exceptions when a message fails (using \Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer).

When there is another normalizer registered to handle exceptions (as in FOSRestBundle the \FOS\RestBundle\Serializer\Normalizer\FlattenExceptionNormalize), there is a conflict of normalizers.

What happens is that the FOSRestBundle serializes the exception, but later the messenger normalizer tries to deserialize it... but since it is a different format, it fails throwing an error.

(this error can heppen any time there is a custom exception normalizer registerd)

How to reproduce

  • application with symfony messenger 5.x and fos rest bundle 3.x
  • throw an error while consuming a message
  • when the message is re-delivered an error is thrown
[2021-02-19T15:07:18.242180+00:00] console.CRITICAL: Error thrown while running command "messenger:consume". Message: "Notice: Undefined index: class" {"exception":"[object] (ErrorException(code: 0): Notice: Undefined index: class at /var/www/app/vendor/symfony/messenger/Transport/Serialization/Normalizer/FlattenExceptionNormalizer.php:74)","command":"messenger:consume","message":"Notice: Undefined index: class"} []

In FlattenExceptionNormalizer.php line 74:

  Notice: Undefined index: class  

Possible Solution

Since it is hard to have independent serializer configurations, what if the \Symfony\Component\Messenger\Transport\Serialization\Normalizer\FlattenExceptionNormalizer was just ignoring errors if the data are different from what is expected?

(from my understanding the ErrorDetailsStamp is used just to provide a nicer error message to the user).

Additional context
I've created FriendsOfSymfony/FOSRestBundle#2292 on the FOSRestBundle repo

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions