8000 add property path to exception message when error writing property · symfony/symfony@473a025 · GitHub
[go: up one dir, main page]

Skip to content

Commit 473a025

Browse files
committed
add property path to exception message when error writing property
1 parent 5c338cc commit 473a025

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

src/Symfony/Component/PropertyAccess/PropertyAccessor.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,22 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
151151
$value = $zval[self::VALUE];
152152
}
153153
} catch (\TypeError $e) {
154-
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0);
154+
self::throwInvalidArgumentException($e->getMessage(), $e->getTrace(), 0, $propertyPath);
155155

156156
// It wasn't thrown in this class so rethrow it
157157
throw $e;
158158
}
159159
}
160160

161-
private static function throwInvalidArgumentException($message, $trace, $i)
161+
private static function throwInvalidArgumentException($message, $trace, $i, $propertyPath)
162162
{
163163
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file'] && isset($trace[$i]['args'][0])) {
164164
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
165165
$pos += strlen($delim);
166166
$type = $trace[$i]['args'][0];
167167
$type = is_object($type) ? get_class($type) : gettype($type);
168168

169-
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given.', substr($message, $pos, strpos($message, ',', $pos) - $pos), $type));
169+
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', substr($message, $pos, strpos($message, ',', $pos) - $pos), $type, $propertyPath));
170170
}
171171
}
172172

src/Symfony/Component/PropertyAccess/Tests/PropertyAccessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ public function testIsWritableForReferenceChainIssue($object, $path, $value)
529529

530530
/**
531531
* @expectedException \Symfony\Component\PropertyAccess\Exception\InvalidArgumentException
532-
* @expectedExceptionMessage Expected argument of type "DateTime", "string" given
532+
* @expectedExceptionMessage Expected argument of type "DateTime", "string" given at property path "date"
533533
*/
534534
public function testThrowTypeError()
535535
{

0 commit comments

Comments
 (0)
0