-
-
Notifications
You must be signed in to change notification settings - Fork 84
Catch error with entrypointlookups in sub-requests #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
32ac4ae
Catch error with entrypointlookups in sub-request by Twig exceptions
ckrack 6b6b731
Listen to kernel.exception
ckrack 0a5e7f9
Provide fix for all sub-requests with requestListener
ckrack 75997bb
Revert "Provide fix for all sub-requests with requestListener"
ckrack File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony WebpackEncoreBundle package. | ||
* (c) Fabien Potencier <[email protected]> | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\WebpackEncoreBundle\EventListener; | ||
|
||
use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent; | ||
use Symfony\WebpackEncoreBundle\Asset\EntrypointLookup; | ||
use Twig_Error_Runtime; | ||
|
||
class ExceptionListener | ||
{ | ||
private $entrypointLookup; | ||
|
||
public function __construct(EntrypointLookup $entrypointLookup) | ||
{ | ||
$this->entrypointLookup = $entrypointLookup; | ||
} | ||
|
||
public function onKernelException(GetResponseForExceptionEvent $event) | ||
{ | ||
$exception = $event->getException(); | ||
|
||
// Reset the entrypointLookup list of previously returned entries, as Twig_Error_Runtime will initialise a sub-request | ||
if ($exception instanceof Twig_Error_Runtime) { | ||
$this->entrypointLookup->reset(); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why this error specifically? All exceptions will result in a full page being rendered (by default). So, I think what you’re doing is trying to detect if the error came from Twig, which is the most likely cause of a situation where Encore assets have been rendered already... and THEN an exception happens. Am I right?
If so... I’m not sure it’s a good idea. Regardless of the error, if we try to render a template for an error page, that should probably use a fresh set of Encore assets.
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 also trying to think if we should limit this to the master request... does the default exception behavior (rendering an error template) happen only on the master request? That seems likely - I just haven’t checked the code yet.
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've thought more about this. I think we should:
Always reset on exception - not just if there was a Twig error. There is going to be some edge cases (people successfully rendering in Twig, then a listener throws an exception after).
We should reset on all requests, not just the master request.
There may still be edge cases - but let's do that and see what happens. Fortunately, this is in "exception" land - so it's already not a normal request.