Skip to content

Commit fd6e0a5

Browse files
patrickmaynardfabpot
authored andcommitted
46867 - add more helpful property path accessor exceptions
1 parent b0ee14e commit fd6e0a5

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)