Skip to content

Commit a8f6af4

Browse files
committed
minor #50128 46867 - add more helpful property path accessor exceptions (patrickmaynard)
This PR was squashed before being merged into the 7.1 branch. Discussion ---------- 46867 - add more helpful property path accessor exceptions | Q | A | ------------- | --- | Branch? | 6.3 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | symfony/symfony#46867 | License | MIT | Doc PR | none Dear reviewers, This small modification adds more helpful exceptions when properties cannot be accessed/set using forms. Only one file was modified, so it should be relatively easy to review. Please feel free to leave a comment if you have any questions about what I'm doing here, and thanks for your work as a reviewer on an open-source project! All the best, Patrick Commits ------- 8d87a672a2 46867 - add more helpful property path accessor exceptions
2 parents 3d545be + fd6e0a5 commit a8f6af4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Extension/Core/DataAccessor/PropertyPathAccessor.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Form\FormInterface;
1717
use Symfony\Component\PropertyAccess\Exception\AccessException as PropertyAccessException;
1818
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
19+
use Symfony\Component\PropertyAccess\Exception\NoSuchPropertyException;
1920
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
2021
use Symfony\Component\PropertyAccess\PropertyAccess;
2122
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
@@ -60,7 +61,11 @@ public function setValue(object|array &$data, mixed $value, FormInterface $form)
6061
// If the data is identical to the value in $data, we are
6162
// dealing with a reference
6263
if (!\is_object($data) || !$form->getConfig()->getByReference() || $value !== $this->getPropertyValue($data, $propertyPath)) {
63-
$this->propertyAccessor->setValue($data, $propertyPath, $value);
64+
try {
65+
$this->propertyAccessor->setValue($data, $propertyPath, $value);
66+
} catch (NoSuchPropertyException $e) {
67+
throw new NoSuchPropertyException($e->getMessage().' Make the property public, add a setter, or set the "mapped" field option in the form type to be false.', 0, $e);
68+
}
6469
}
6570
}
6671

0 commit comments

Comments
 (0)