-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Fix: Original Throwable get lost during component render #2030
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: $e
is used instead ofprevious: $e->getPrevious()