This would give us a nice looking error page with more readable stack trace. See attached screenshots.

The symfony/debug component is already included in Drupal code base as it is a dependency of symfony/http-kernel and symfony/console components.

CommentFileSizeAuthor
after.png104.42 KBchi
before.png72.19 KBchi

Comments

Chi created an issue. See original summary.

chi’s picture

I suppose this will require revising the entire error management system which by the way hasn't got much attention since Drupal 6.
https://git.drupalcode.org/project/drupal/blob/8.8.x/core/includes/error...

cilefen’s picture

The before and after screenshots contain the same information. If this involves revisiting the entire error management system and adds a dependency, is this really worth doing?

Even better: https://github.com/filp/whoops

chi’s picture

@cilefen those screenshots are only about exceptions. PHP errors (warnings, notices) are shown as messages in Drupal which makes the difference.

chi’s picture

Here is a simple way to enable Symfony Debug handlers on Drupal 8 site.

  1. Add symfony/debug as dev dependency to composer.json file (not required but recommended)
    composer require --dev symfony/debug
  2. Enable debugging in local settings.php file
    Debug::enable();
  3. Replace FinalExceptionSubscriber in development.services.yml with empty implementation
    services:
      exception.final:
        class: stdClass
    

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

chi’s picture

The debug component has been removed in favor of the new ErrorHandler component.
https://symfony.com/doc/4.4/components/error_handler.html

That works for me.

$error_handler = Debug::enable();
// Override exception handler set by DrupalKernel::bootEnvironment().
$error_handler->setExceptionHandler([$error_handler, 'renderException']);
chi’s picture

andypost’s picture

voleger’s picture

I think we also need to introduce an error handler template to be able to keep the existing error logging settings behavior.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

prudloff’s picture

We created a contrib module that does that: https://www.drupal.org/project/symfony_debug

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

voleger’s picture

Title: Replace error and exception handlers with implementation from Symfony Debug component » Replace error and exception handlers with implementation from Symfony ErrorHandler component

Debug component is deprecated since Symfony 4.4. Instead, use the ErrorHandler component.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kevinquillen’s picture

+1 this is a fantastic idea.

I was getting Ignition integrated earlier after seeing that package thinking it would be a great DX enhancement. I love how you can add solution links with your custom exceptions - really useful for guiding users to getting help or answers on what they encountered instead of a dead end stop.

I think Drupal would really benefit from revamping its error handler along these lines. It would go a long way to helping less technical users/devs find answers or links to docs from an error screen (perhaps also baking in links to Drupal slack, etc).

steinmb’s picture

Version: 9.4.x-dev » 10.0.x-dev

+1
I guess we are aiming for minimum Symfony 5 here, if so, we need to target 10.x with this change.

quietone credited sun.

quietone’s picture

I have closed #1722694: Fixed Kernel::init() overrides Drupal's error handling configuration which was re-opened to "Replace Drupal's error handling with Symfony/HttpKernel's". At the time sun commented on what to do next. Noting it here in case it is useful.

Also, adding the related issue from that issue.

aaronmchale’s picture

bradjones1’s picture

Version: 10.0.x-dev » 10.1.x-dev
Related issues: +#1537198: Add a Production/Development toggle

We would want to ideally use the debug flag set on the kernel, see #1537198: Add a Production/Development toggle

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.