8000 The error handling is inconsistent in the serializer decoders · Issue #9393 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
The error handling is inconsistent in the serializer decoders #9393
Closed
@stof

Description

@stof

Here is what happens currently:

  • the ChainDecoder throws a Symfony\Component\Serializer\Exception\RuntimeException when it cannot find a decoder for the format (and then an exception thown by the decoder being used)
  • the XmlEncoder throws a Symfony\Component\Serializer\Exception\UnexpectedValueException on failure
  • the JsonDecode and JsonEncoder fail silently (you get null as value) and then provide a method to get the json decoding error code (not the same name in them btw), which is not part of the interface (making the method hard to use as we don't have any way to access it when it is used in the serializer)
  • the Serializer just proxies the call to its ChainDecoder so the behavior is the same.

Both exceptions used here implement the exception interface of the component.

My suggestion is to refactor the json decoder classes to make them throw the UnexpectedValueException on failure like the xml format instead of using a separate method which cannot be accessed.
The phpdoc of the interface should also be updated to document the expected behavior on failure, which is currently not specified

Metadata

Metadata

Assignees

No one assigned

    Labels

    EnhancementGood first issueIdeal for your first contribution! (some Symfony experience may be required)Serializer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0