Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd871473

Browse files
committed
feature#27586 [PropertyAccess] Add Property Path to Exception Message (rodnaph)
This PR was merged into the 4.2-dev branch.Discussion----------[PropertyAccess] Add Property Path to Exception Message| Q | A| ------------- | ---| Branch? | master| Bug fix? | no| New feature? | yes| BC breaks? | no| Deprecations? | no| Tests pass? | yes| Fixed tickets | None| License | MIT| Doc PR | NoneWhen an exception is thrown writing a property it is not currently obvious which path is at fault (eg. `Expected argument of type "%s", "%s" given` - but where?). This patch appends the current property path to the exception so it is clear which path caused the error (eg. `Expected argument of type "%s", "%s" given at property path "foo.bar"`)Commits-------473a025 add property path to exception message when error writing property
2 parents5fe78a3 +473a025 commitd871473

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-
privatestaticfunctionthrowInvalidArgumentException($message,$trace,$i)
161+
privatestaticfunctionthrowInvalidArgumentException($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-
thrownewInvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given.',substr($message,$pos,strpos($message,',',$pos) -$pos),$type));
169+
thrownewInvalidArgumentException(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
publicfunctiontestThrowTypeError()
535535
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp