Skip to content
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

Merged
merged 1 commit into from
Aug 20, 2024

Conversation

cuchac
Copy link
Contributor

@cuchac cuchac commented Aug 7, 2024

Q A
Bug fix? yes
New feature? no
Issues
License MIT

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 of previous: $e->getPrevious()

@carsonbot carsonbot added Bug Bug Fix Status: Needs Review Needs to be reviewed labels Aug 7, 2024
@smnandre
Copy link
Member

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 ?
I'll check on my side to find why i went back :)

@cuchac
Copy link
Contributor Author

cuchac commented Aug 15, 2024

Hello @smnandre

when I for example access undefined variable inside component PHP file, I will get following error page:
image

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.

@smnandre
Copy link
Member

Just wondering, what if you remove entirely this block (i'm not remembering why it's there is the first place)

if (!($e instanceof \Exception)) {
    // ... 
}

@smnandre
Copy link
Member

Comment on lines 123 to 125
if (!($e instanceof \Exception)) {
$e = new \Exception($e->getMessage(), $e->getCode(), $e->getPrevious());
$e = new \Exception($e->getMessage(), $e->getCode(), $e);
}
Copy link
Contributor Author

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.

Copy link
Member

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.

@cuchac
Copy link
Contributor Author

cuchac commented Aug 16, 2024

Just wondering, what if you remove entirely this block (i'm not remembering why it's there is the first place)

if (!($e instanceof \Exception)) {
    // ... 
}

If I delete that if, it will fix my issue. I believe it can be deleted.

@cuchac
Copy link
Contributor Author

cuchac commented Aug 16, 2024

Hello @smnandre, I've changed the PR to remove the problematic if.

@smnandre
Copy link
Member

@kbond if you have time to check, i'm not sure if the initial reasons still apply.. but it feels like a good idea :)

@cuchac
Copy link
Contributor Author

cuchac commented Aug 17, 2024

@smnandre I've looked at the original commit and I don't see any reason for that if statement. I understand why Twig RuntimeException should be thrown, but I don't understand why "repack" non-exceptions. I believe it was mistake from the beginning.

@kbond
Copy link
Member

kbond commented Aug 20, 2024

Thanks for this Joe. I'm not sure why this was done previously but this is the right move.

@kbond kbond merged commit 70c68d8 into symfony:2.x Aug 20, 2024
41 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug Bug Fix Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants