Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[PropertyAccessor] remove try/catch or provide context into re-thrown exception #34899

Closed
@Pictor13

Description

@Pictor13

I just had some debugging problem, when the PropertyAccessor is called from the Form component.

Specifically, the call to PropertyAccessor::writeProperty() is wrapped in a try/catch block and, in case of exception, it is re-thrown manually by the static method throwInvalidArgumentException().

Except for providing a namespaced custom exception, I am not sure why the try/catch is there, since I suppose that anybody would want the original error to be reported, when trying to set a property on target object/array.

In fact, re-throwing hinders the discovery of the actual problem, breaking the call-stack at the setValue () call instead of reporting what went wrong. Not really debuggable.
This is a screenshot from my specific case:

Screenshot 2019-12-09 at 19 10 40

"Expected argument of type "%s", "%s" given at property path "%s".

...after which I am left with guess work.
The re-thrown error message was too specific and not providing the context (File + Line where the real exception happened).

I am not sure about the benefits of re-throwing here.
So I am asking if it is possible to remove the try/catch.
Or eventually to change the re-throwing to at least report all the information provided from the original exception, rather than hiding them (atm the message doesn't help if we don't get the info of where this is happening).

What do you think about that?
Does it make sense?

Metadata

Metadata

Assignees

No one assigned

    Labels

    DXDX = Developer eXperience (anything that improves the experience of using Symfony)PropertyAccess

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions