Error::formatBacktrace() returns wrong output

Created on 12 April 2023, over 1 year ago
Updated 13 April 2023, over 1 year ago

Here is example of how exceptions are printed in Drupal.

The website encountered an unexpected error. Please try again later.

Exception: Test in Drupal\system\Form\SiteInformationForm->buildForm() (line 96 of core/modules/system/src/Form/SiteInformationForm.php).
call_user_func_array() (Line: 534)
Drupal\Core\Form\FormBuilder->retrieveForm() (Line: 281)
Drupal\Core\Form\FormBuilder->buildForm() (Line: 73)
Drupal\Core\Controller\FormController->getContentResult()
call_user_func_array() (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 698)
Drupal\Core\DrupalKernel->handle() (Line: 19)

There are a few issues with above output.
The main one is that it prints line numbers but no file names where those lines are located. Furthermore, if you try to locate those file by class names you will find that line numbers don't match the files. That's very confusing.

Another issue is how Error::formatBacktrace() renders arguments. It doesn't provide information about object types and
converts boolean to integers like follows.
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Such output is completely useless. Note that most users will unlikely see those arguments at all because arguments are only provided if zend.exception_ignore_args = On (since PHP 7.4). I guess most PHP installations have this value disabled by default (production mode).

🐛 Bug report
Status

Needs work

Version

10.1

Component
Base 

Last updated about 13 hours ago

Created by

🇷🇺Russia Chi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024