Score:1

How do I get the un-truncated error message from dblog?

ru flag

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.

Score:2
cn flag

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).

https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug

xdebug

ru flag
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.
cn flag
@Hudri assuming you have a decent IDE that shouldn’t be an issue, eg https://www.jetbrains.com/help/phpstorm/debugging-with-php-exception-breakpoints.html
4uk4 avatar
cn flag
@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
ru flag
Oh, thanks a lot, I did not know Exception Breakpoints yet in PHPstorm, this will help greatly
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.