minor #31049 [Serializer] [DX] NotNormalizableValueException should note which attribute failed to denormalize when possible (Simperfit)

This PR was merged into the 4.3-dev branch.

Discussion
----------

[Serializer] [DX] NotNormalizableValueException should note which attribute failed to denormalize when possible

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no <!-- don't forget to update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #29230   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR

<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

This is the idea of a fix discussed with @stof about the improvment of serializer error message.  Now we can try a implementation lis this one. This is linked to EUFOSSA even if this has been done not in the hackathon.

Commits
-------

59942b40d1 [Serializer] [DX] NotNormalizableValueException should note which attribute failed to denormalize when possible
This commit is contained in:
Fabien Potencier 2019-04-29 08:58:33 +02:00
commit 0cd5c18e7f

View File

@ -355,7 +355,7 @@ abstract class AbstractObjectNormalizer extends AbstractNormalizer
try {
$this->setAttributeValue($object, $attribute, $value, $format, $context);
} catch (InvalidArgumentException $e) {
throw new NotNormalizableValueException($e->getMessage(), $e->getCode(), $e);
throw new NotNormalizableValueException(sprintf('Failed to denormalize attribute "%s" value for class "%s": %s.', $attribute, $class, $e->getMessage()), $e->getCode(), $e);
}
}