0

How can you extract relevant information from a verbose log ?

We encounter a problem after merging a feature branch so I understand something is wrong with a strip_tags function but have many of them and I'm not sure how to locate it ?

Here is the verbose log:

  TypeError : strip_tags(): Argument #1 ($string) must be of type string, array given dans strip_tags() (/opt/www/website/vendor/twig/twig/src/Extension/CoreExtension.php ligne 1120)
  #0 /opt/www/website/vendor/twig/twig/src/Extension/CoreExtension.php(1120): strip_tags()
  #1 /opt/www/website/vendor/twig/twig/src/Environment.php(418) : eval()'d code(45): twig_striptags()
  #2 /opt/www/website/vendor/twig/twig/src/Template.php(405): __TwigTemplate_828c353f185da3d0ee07c237d52f8b71->doDisplay()
  #3 /opt/www/website/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
  #4 /opt/www/website/vendor/twig/twig/src/Template.php(390): Twig\Template->display()
  #5 /opt/www/website/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render()
  #6 /opt/www/website/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
  #7 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render()
  #8 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
  #9 /opt/www/website/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\Core\Render\Renderer->render()
  #10 /opt/www/website/vendor/twig/twig/src/Environment.php(418) : eval()'d code(84): Drupal\Core\Template\TwigExtension->escapeFilter()
  #11 /opt/www/website/vendor/twig/twig/src/Template.php(405): __TwigTemplate_1da0c7e2719fe3d1360f786423ae5a4f->doDisplay()
  #12 /opt/www/website/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
  #13 /opt/www/website/vendor/twig/twig/src/Template.php(390): Twig\Template->display()
  #14 /opt/www/website/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render()
  #15 /opt/www/website/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
  #16 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render()
  #17 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
  #18 /opt/www/website/web/core/lib/Drupal/Core/Template/TwigExtension.php(581): Drupal\Core\Render\Renderer->render()
  #19 /opt/www/website/vendor/twig/twig/src/Environment.php(418) : eval()'d code(67): Drupal\Core\Template\TwigExtension->renderVar()
  #20 /opt/www/website/vendor/twig/twig/src/Template.php(405): __TwigTemplate_7bc7e5b97e351993541b90225f7a21b5->doDisplay()
  #21 /opt/www/website/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
  #22 /opt/www/website/vendor/twig/twig/src/Template.php(390): Twig\Template->display()
  #23 /opt/www/website/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render()
  #24 /opt/www/website/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
  #25 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render()
  #26 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
  #27 /opt/www/website/web/core/modules/views/src/Plugin/views/field/FieldPluginBase.php(1160): Drupal\Core\Render\Renderer->render()
  #28 /opt/www/website/web/core/modules/views/views.theme.inc(238): Drupal\views\Plugin\views\field\FieldPluginBase->advancedRender()
  #29 [internal function]: template_preprocess_views_view_field()
  #30 /opt/www/website/web/core/lib/Drupal/Core/Theme/ThemeManager.php(287): call_user_func_array()
  #31 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render()
  #32 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
  #33 /opt/www/website/web/core/modules/views/src/Plugin/views/field/FieldPluginBase.php(1746): Drupal\Core\Render\Renderer->render()
  #34 /opt/www/website/web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(777): Drupal\views\Plugin\views\field\FieldPluginBase->theme()
  #35 [internal function]: Drupal\views\Plugin\views\style\StylePluginBase->elementPreRenderRow()
  #36 /opt/www/website/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array()
  #37 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(788): Drupal\Core\Render\Renderer->doTrustedCallback()
  #38 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(374): Drupal\Core\Render\Renderer->doCallback()
  #39 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
  #40 /opt/www/website/web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(716): Drupal\Core\Render\Renderer->render()
  #41 /opt/www/website/web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(582): Drupal\views\Plugin\views\style\StylePluginBase->renderFields()
  #42 /opt/www/website/web/core/modules/views/src/Plugin/views/style/StylePluginBase.php(473): Drupal\views\Plugin\views\style\StylePluginBase->renderGrouping()
  #43 /opt/www/website/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2169): Drupal\views\Plugin\views\style\StylePluginBase->render()
  #44 /opt/www/website/web/core/modules/views/src/ViewExecutable.php(1538): Drupal\views\Plugin\views\display\DisplayPluginBase->render()
  #45 /opt/www/website/web/core/modules/views/src/Plugin/views/display/DisplayPluginBase.php(2459): Drupal\views\ViewExecutable->render()
  #46 /opt/www/website/web/core/modules/views/src/ViewExecutable.php(1667): Drupal\views\Plugin\views\display\DisplayPluginBase->preview()
  #47 /opt/www/website/web/core/modules/views/src/Element/View.php(66): Drupal\views\ViewExecutable->preview()
  #48 [internal function]: Drupal\views\Element\View::preRenderViewElement()
  #49 /opt/www/website/web/core/lib/Drupal/Core/Security/DoTrustedCallbackTrait.php(101): call_user_func_array()
  #50 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(788): Drupal\Core\Render\Renderer->doTrustedCallback()
  #51 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(374): Drupal\Core\Render\Renderer->doCallback()
  #52 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
  #53 /opt/www/website/web/core/lib/Drupal/Core/Template/TwigExtension.php(479): Drupal\Core\Render\Renderer->render()
  #54 /opt/www/website/vendor/twig/twig/src/Environment.php(418) : eval()'d code(198): Drupal\Core\Template\TwigExtension->escapeFilter()
  #55 /opt/www/website/vendor/twig/twig/src/Template.php(405): __TwigTemplate_4dd72451c5fb2f7d4a2875740332ec7f->doDisplay()
  #56 /opt/www/website/vendor/twig/twig/src/Template.php(378): Twig\Template->displayWithErrorHandling()
  #57 /opt/www/website/vendor/twig/twig/src/Template.php(390): Twig\Template->display()
  #58 /opt/www/website/web/core/themes/engines/twig/twig.engine(55): Twig\Template->render()
  #59 /opt/www/website/web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template()
  #60 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(433): Drupal\Core\Theme\ThemeManager->render()
  #61 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(204): Drupal\Core\Render\Renderer->doRender()
  #62 /opt/www/website/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(242): Drupal\Core\Render\Renderer->render()
  #63 /opt/www/website/web/core/lib/Drupal/Core/Render/Renderer.php(580): Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}()
  #64 /opt/www/website/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(243): Drupal\Core\Render\Renderer->executeInRenderContext()
  #65 /opt/www/website/web/core/lib/Drupal/Core/Render/MainContent/HtmlRenderer.php(132): Drupal\Core\Render\MainContent\HtmlRenderer->prepare()
  #66 /opt/www/website/web/core/lib/Drupal/Core/EventSubscriber/MainContentViewSubscriber.php(90): Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse()
  #67 [internal function]: Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
  #68 /opt/www/website/web/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php(142): call_user_func()
  #69 /opt/www/website/vendor/symfony/http-kernel/HttpKernel.php(174): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch()
  #70 /opt/www/website/vendor/symfony/http-kernel/HttpKernel.php(81): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
  #71 /opt/www/website/web/modules/contrib/redirect_after_login/src/RedirectMiddleware.php(46): Symfony\Component\HttpKernel\HttpKernel->handle()
  #72 /opt/www/website/web/core/lib/Drupal/Core/StackMiddleware/Session.php(58): Drupal\redirect_after_login\RedirectMiddleware->handle()
  #73 /opt/www/website/web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
  #74 /opt/www/website/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
  #75 /opt/www/website/web/core/modules/page_cache/src/StackMiddleware/PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass()
  #76 /opt/www/website/web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle()
  #77 /opt/www/website/web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
  #78 /opt/www/website/vendor/stack/builder/src/Stack/StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
  #79 /opt/www/website/web/core/lib/Drupal/Core/DrupalKernel.php(718): Stack\StackedHttpKernel->handle()
  #80 /opt/www/website/web/index.php(19): Drupal\Core\DrupalKernel->handle()
  #81 {main}
5
  • There isn't really a formula for reading a stack trace - usually it's a matter of going down the list until you find something that looks familiar, and investigating. If you see code from a custom module/theme involved, that's normally a good indicator. Then, or if nothing looks familiar, fire up the debugger and start setting breakpoints on the offending lines, so you can get a better idea of what variables are in context at the time of the failure. Compare the findings with what you know about the site (custom features, advanced Views setup, etc), and eventually you'll whittle it down
    – Clive
    Commented Jun 1 at 19:45
  • You'd also want to compare findings to what changed in the offending merge specifically, in fact that's probably a more efficient starting point. For example, the last interaction in the stack trace before the theme layer is with a Views field plugin, so check the merge which caused the problem for any changes that could affect Views field plugins
    – Clive
    Commented Jun 1 at 19:48
  • Use a PHP debugger like xdebug.
    – mona lisa
    Commented Jun 1 at 20:03
  • I'd scan the whole codebase for that exact string |strip_tags. There can't be too many places. First custom themes and modules, next contrib, next core. Temporarily remove some of them until the problem is gone. Try to isolate it. Switch things on and off until you get it. Try to reproduce it in a fresh installation.
    – leymannx
    Commented Jun 1 at 20:36
  • Here the problem is that the twig function is |striptags, so the trace is not even precise on this mater. And going down the list I see nothing familiar, only internal Drupal function, hence my question/doubt.
    – tostinni
    Commented Jun 2 at 2:51

2 Answers 2

2

This is tricky because you get a run-time error from a compiled twig template. All compiled templates are in /sites/default/files/php/twig/. Look for the class (line #2):

class __TwigTemplate_828c353f185da3d0ee07c237d52f8b71 extends Template

The path to this PHP file will tell you the real Twig template name, unless it is an inline template defined in PHP. Then go further down the stack trace to locate the inline template. This describes post-mortem debugging, using only the information provided in your question.

Locate template with Xdebug

However, if you reproduce the error locally use an IDE with Xdebug. This makes this whole process much faster because you can stop on exceptions, click on variables and stack trace. In this case, you find the full file name of the Twig template with the line number in the exception variable $e when the code stops the first time (enable stopping on exceptions in the IDE). This stop is in the class mentioned, now only in memory and not as file. Look at the variable $this.


Locate template without Xdebug

If you don't have Xdebug you can display/log the more helpful Twig runtime error by removing line #47 throw $previous_exception; in web/core/themes/engines/twig/twig.engine:

function twig_render_template($template_file, array $variables) {
  ...
  catch (RuntimeError $e) {
    // In case there is a previous exception, re-throw the previous exception,
    // so that the original exception is shown, rather than
    // \Twig\Template::displayWithErrorHandling()'s exception.
    $previous_exception = $e->getPrevious();
    if ($previous_exception) {
      // throw $previous_exception;
    }
    throw $e;
  }
  ...
}

The error message looks then like this:

Twig\Error\RuntimeError: An exception has been thrown during the rendering of a template
("strip_tags(): Argument #1 ($string) must be of type string, array given").
in Twig\Template->displayWithErrorHandling()
(line 123 of /var/www/myproject/web/themes/custom/mytheme/layout/page.html.twig).
3
  • I initially hadn't this folder, I removed settings.local.php and sites/default/files/php has been created but it's empty, so I'm not sure where those templates are stored then... Am I missing something in my setup that prevent this cache from being generated ?
    – tostinni
    Commented Jun 2 at 2:55
  • They are compiled on demand and then stored. You can force that with drush twig-compile. If nothing is stored you have disabled that in your local dev settings. But if this is local debugging then you can use Xdebug where it stops at the original exception with the full template name and line number.
    – 4uk4
    Commented Jun 2 at 6:58
  • Thks for the command, but it seems there was another error also, so this hand't helped us. I guess we'll try to set up Xdebug to avoid losing time on trivial error like this one.
    – tostinni
    Commented Jun 4 at 1:37
0

We finally managed to find the culprit template where we had a content.field_xxx|striptags.

We found it removing all the templates one folder at the time and detecting when the site was not displaying the error anymore.

3
  • 1
    OK, I wondered why Xdebug shows the Twig error and the Drupal logs don't. I've found the line responsible. So without Xdebug you could temporarily remove this line and get the template name and line number. See the edited answer.
    – 4uk4
    Commented Jun 4 at 7:22
  • Thank you for the suggestion, but on our project it doesn't seem to make any change, that's quite weird :/
    – tostinni
    Commented Jun 8 at 4:22
  • That would be interesting to step through the code with Xdebug to discover why the debugging method without Xdebug doesn't work.
    – 4uk4
    Commented Jun 8 at 6:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.