8000 [PropertyAccessor] Missing TypeError catch · Issue #45199 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content < 10000 /span>
[PropertyAccessor] Missing TypeError catch #45199
Closed
@b1rdex

Description

@b1rdex

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

      0