The "Recent log messages" is very handy to track down errors on sites. While this works great for errors in PHP code, it is often unhelpful for errors in Twig code. E.g. I've this error message in my log:

User error: "attributes" is an invalid render array key in Drupal\Core\Render\Element::children() (Zeile 98 in /web/core/lib/Drupal/Core/Render/Element.php)

#0 /web/core/includes/bootstrap.inc(346): _drupal_error_handler_real(256, '"attributes" is...', '/var/www/vhosts...', 98) #1 [internal function]: _drupal_error_handler(256, '"attributes" is...', '/var/www/vhosts...', 98, Array)

(47 more lines here)

This strack trace has 47 points, most of them from Drupal core. The error is obviously in my custom theme.

#11 /web/core/lib/Drupal/Core/Theme/ThemeManager.php(384): twig_render_template('themes/custom/w...', Array)

Due this line I suspect one of my custom Twig templates is incorrect, but I can't figure out which one, due the truncated filename.

How can I get the full error message of one specific line in the stack trace? If I would know the full name of the file mentioned in line #11, it would greatly help me to fix my error.

1 Answer 1


You are getting the result of PHP built-in backtracing. Drupal is using debug_backtrace() for displaying and Exception::getTraceAsString was added for logging in Drupal 8.2.x. See the change record. The second one is a very fast and efficient backtracing method, it doesn't run out of memory when handling deeply nested code which is typically for Drupal rendering templates. However, it might not provide all information you are looking for.

If you need a fully working stack trace use Xdebug to catch the exception (no breakpoint needed).



  • But Xdebug doesn't really help in a case like this. Setting a breakpoint on a core function that is called a million times during a request is unreasonable.
    – Hudri
    Feb 15, 2022 at 12:57
  • @Hudri assuming you have a decent IDE that shouldn’t be an issue, eg jetbrains.com/help/phpstorm/…
    – Clive
    Feb 15, 2022 at 13:07
  • @Hudri, Twig errors are catchable in Symfony. You could write your own code to format the backtrace and override /core/lib/Drupal/Core/EventSubscriber/ExceptionLoggingSubscriber.php
    – 4uk4
    Feb 15, 2022 at 13:13
  • Oh, thanks a lot, I did not know Exception Breakpoints yet in PHPstorm, this will help greatly
    – Hudri
    Feb 15, 2022 at 14:05

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.