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

Appearance settings

[PropertyAccessor] Missing TypeError catch #45199

Copy link
Copy link
Closed
@b1rdex

Description

@b1rdex
Issue body actions

Symfony version(s) affected

6.0.2

Description

I stumbled upon a TypeError: Cannot assign string to property App\Api\Model\Request\CoordsCheckerRequest::$latitude of type float.

Browsing the code, I see there is a TypeError -> InvalidArgumentException wrapper:
https://github.com/symfony/symfony/blob/6.0/src/Symfony/Component/PropertyAccess/PropertyAccessor.php#L206-L217

Looks like another one should be added there.

How to reproduce

class CoordsCheckerRequest {
    public float $longitude;
}

$accessor = new PropertyAccessor();
$request = new CoordsCheckerRequest();
$accessor->setValue($request, 'longitude', 'foo');

Possible Solution

if (preg_match('/^Cannot assign (\S+) to property \S+::\$\S+ of type (\S+)$/', $message, $matches)) {
    [, $actualType, $expectedType] = $matches;

    throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $expectedType, 'NULL' === $actualType ? 'null' : $actualType, $propertyPath), 0, $previous);
}

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.