Fix: Original Throwable get lost during component render#2030
Fix: Original Throwable get lost during component render#2030kbond merged 1 commit intosymfony:2.xfrom
Conversation
|
Hi @cuchac I remember i almost made the same change .... and reverted because other scenarios made it not better... but don't remember precisely why/when. So... let's solve this :) Do you have a simple scenario / use case that we can reproduce to play around ? |
|
Hello @smnandre when I for example access undefined variable inside component PHP file, I will get following error page: There are two stack traces but the original stack trace that can be used to solve the issue is lost. Without stack trace I can only guess where the problem inside the component is. |
|
Just wondering, what if you remove entirely this block (i'm not remembering why it's there is the first place) |
|
Found the context / reasons here: |
| if (!($e instanceof \Exception)) { | ||
| $e = new \Exception($e->getMessage(), $e->getCode(), $e->getPrevious()); | ||
| $e = new \Exception($e->getMessage(), $e->getCode(), $e); | ||
| } |
There was a problem hiding this comment.
I believe this whole part is useless. Why converting Throwable to Exception? RuntimeError can have Throwable as previous parameter. Wrapping Throwables in Twig RuntimeError is correct in my opinion, but wrapping Throwables in another Exception is useless, it just adds another stacktrace and also causes the problem with lost original stack trace because of $e->getPrevious() error.
There was a problem hiding this comment.
I'm feeling the same, with no absolute certitude of the scenarios that probably justified this in the first place.
If I delete that |
|
Hello @smnandre, I've changed the PR to remove the problematic |
|
@kbond if you have time to check, i'm not sure if the initial reasons still apply.. but it feels like a good idea :) |
|
@smnandre I've looked at the original commit and I don't see any reason for that |
|
Thanks for this Joe. I'm not sure why this was done previously but this is the right move. |

When non-Exception Throwable is thrown during component rendering, original Throwable is lost together with it's stacktrace. Without stacktrace it is hard to debug the problem. This simple change fixes the problem in the same way as in https://github.com/cuchac/ux/blob/f69b9656f318464253590a6575da65f34262d931/src/TwigComponent/src/Twig/ComponentExtension.php#L127 where
previous: $eis used instead ofprevious: $e->getPrevious()