[PropertyAccessor] remove try/catch
or provide context into re-thrown exception
#34899
Labels
DX
DX = Developer eXperience (anything that improves the experience of using Symfony)
PropertyAccess
I just had some debugging problem, when the PropertyAccessor is called from the Form component.
Specifically, the call to
PropertyAccessor::writeProperty()
is wrapped in atry/catch
block and, in case of exception, it is re-thrown manually by the static methodthrowInvalidArgumentException()
.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:
...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?
The text was updated successfully, but these errors were encountered: