Hello,
since f2e5f40 I get An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0"). which makes it impossible to display any template.
The problem comes from the modification made in lib/Twig/Profiler/NodeVisitor/Profiler.php.
I don't have a solution nor an idea as to why it crashes, I hope someone can fix this quickly.
can you give the stack trace of the exception ?
Found this (I removed the beginning of paths) :
request.CRITICAL: Exception thrown when handling an exception (Twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0"). at Resources/views/Exception/exception_full.html.twig line 1) {"exception":"[object] (Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"Notice: Undefined offset: 0\"). at Resources/views/Exception/exception_full.html.twig:1, Symfony\Component\Debug\Exception\ContextErrorException(code: 0): Notice: Undefined offset: 0 at vendor/twig/twig/lib/Twig/Extension/Profiler.php:23)"} []
Line 1 of the exception_full.html.twig is the {% extends 'TwigBundle::layout.html.twig' %}
Is that what you needed ?
@fabpot looks like it is possible to put the Profiler extension in an invalid state by having 0 actives profiles in some cases
I ran into the same issue today after an update.
Templating doesn't work anymore in dev.
Tried to debug the enter / leave methods of the Profiler, didn't understand why but at some point it gets messy and as @stof said, the $actives property is empty.
Any news on this problem ? This is quite troublesome.
@NVasse can you provide a reproducer? or even better, debug the issue? That would help a lot.
Forgot to mention that I use the 1.x branch, I don't know if the problem occurs on the 2.x
@nicolas-grekas You only need to update 1.x branch to the latest and work on dev environment, nothing special. I'll try to take a look but I don't have any free time and I'm not even sure I could debug the problem. This would be quicker if someone familiar with Twig code debugs it.
I guess there is something special about your environment that triggers the error and thus having a small reproducable application would help a lot. If this would be a common issue, I would have expected more reports like this.
Closing as it does not seem to be an issue on Twig itself. Without a reproducer, it's not possible to do anything anyway.
@stof Could you link me or tell me about these active profiles so I can try to find a solution ? I'm not sure what this is about especially since it used to work just fine before that commit.
Hi all,
after update of my sf project I have the same error. Here the twig update details :
I also ran into the issue of templating not working in dev. Everything is fine in prod. This triggered after updating my php version from 5.6 to 7.1 and running my app that uses Symfony 3.3.4.
Someone will have to provide a reproducer or a fix. "Me too" is not enough ...
the problem is this update
Updating twig/twig (v2.4.4 => v2.4.5): Downloading (100%)
I installed 2.4.4 again and the problem disappear
I also have this problem , it happened when I update twig to twig/twig v2.4.5 , I think we should reopen this issue, I downgrade twig to v2.4.4, it works as expected.
Yup same. Downgrading to 2.4.4 did the trick.
Same problem here, have to downgrade 2.4.5 to 2.4.4
Hi, first time i have this kind of problem. Someone could explain me how to downgrade to 2.4.4
I ran into this problem too now. But only after doing composer require --dev debug
Also switching to prod mode makes the problem disappear.
Can you confirm this, so we are talking bout the same issue here?
Hi,
Same here. The problem appeared only in dev mode after updating Twig 2.4.5.
A project with Symfony 4.0.5 on PHP 7.2.3.
In vendor/lib/twig/twig/lib/Twig/Extension/Profiler.php (line 23) :
$this->actives[0]->addProfile($profile);
$this->activates[0] seems not to be set some time.
Hope this help.
Had the same issue on a new project with twig 2.4.5. When I wanted to give you a minimum reproducible I noticed that if I cloned the project fresh, I did not have the issue. Don't know if this helps, but may offer some more insight.
Reproducer:
composer create-project symfony/skeleton bug
composer require server --dev
composer require --dev debug
composer require twig
php bin/console server:run
http://localhost:8000/
I have a symfony 3.4 application, ran composer update this morning where twig updated from 2.4.4 to 2.4.5 and now I'm facing the same issue.
After I downgraded my twig to 2.4.4 the error is gone.
same for me
composer create-project symfony/skeleton bug
composer req twig
composer req profiler
Effectively, i had twig v2.4.5 on sf 4.0.5.
I downgraded to v2.4.4 and the whole thing works properly again !
downgraded to 2.4.4 (sf 3.4) and everything is ok now.
There is some issue in \twig\twig\lib\Twig\Extension\Profiler.php on line 23
$this->actives suppose to be an array of "Twig_Profiler_Profile" objects. But it is an empty array which means index 0 is not there.
This also explains that this issue is not in prod mode, only in dev mode because profiler works only in dev mode.
The problem is in the file Twig_Profiler_NodeVisitor_Profiler. I changed line 56 from:
return sprintf('__internal_%s', hash('sha256', __METHOD__));
to:
return sprintf('__internal_%s', hash('sha256', __METHOD__.$this->extensionName));
And after clearing the twig cache it works again.
@Shoplifter's steps allowed me to reproduce the issue. I have pushed an example application at https://github.com/xabbuh/twig-2627 if someone wants to work on this issue.
(4/4)聽Twig_Error_RuntimeAn exception has been thrown during the rendering of a template ("Notice: Undefined offset: 0").
--
Removed profiler temporary, because can not downgrade twig if using twig-bundle
@xabbuh I cloned your bug repo, ran composer install and started php server.
But then I got a different error: Twig_Error_Runtime
An exception has been thrown during the rendering of a template ("Object not found").
.. which is already filed here https://github.com/twigphp/Twig/issues/2643
maybe the two are related?
same problem here, can someone please explain how to downgrade to twig 2.4.4?!
@PhilETaylor Thank you - https://github.com/twigphp/Twig/pull/2645 worked for me
can someone please explain how to downgrade to twig 2.4.4?!
Add this to your composer.json, do a composer update, and a cache clear.
"twig/twig": "2.4.4",
or, if you have a "twig/twig" entry in your composer.json just remove it completely, do a composer update, and a cache clear and let Symfony decide which version to install (Symfony 3.4.4 demands Twig 2.4.4 in its composer.json)
Thanks it worked for me, hope they accept your pull request
@PhilETaylor I ran into this installing skeleton (symfony 4.0.5) and then require twigand debug --dev
see this reproducer https://github.com/xabbuh/twig-2627
so this bug matters for current Symfony installations since symfony has no upper constraint for twig
@Shoplifter yup, but my experience day to day ends at 3.4.* due to dependancies not rushing to provide a Symfony 4 compatible version :-) :-)
1.35.2 and 2.4.6 are out and fixes this issue.
It is available now? Can i update to the new version?
Thank you
It is, thank you!
I Had the same problem, and I updated to last version and now is working for me,
cache
Most helpful comment
1.35.2 and 2.4.6 are out and fixes this issue.