1

In one case I got in all webpages of my website this exception (error):

An unexpected error occurred. Please try again later

At first, I didn't know how to debug this but after doing some reading I have checked the SQL table watchdog and there I only saw a few "Page not found" errors without further detailing, but after running vendor/bin/drush watchdog:show I got this

------- -------------- ---------------- ---------- -------------------------------------------------------------------------------------------
  ID      Date           Type             Severity   Message
 ------- -------------- ---------------- ---------- -------------------------------------------------------------------------------------------
  85934   16/Dec 17:21   php              error      Twig\Error\SyntaxError: Unknown "endif" tag. in Twig\Parser->subparse() (line 37 of
                                                     /home/USERNAME/WEB_APPLICATION_ROOT/example.com/web/themes/contrib/basic/templates/layout/html.html.twig).

This helped me to debug the problem by editing the aforementioned Twig file.

How to debug Drupal especially when no webserver logs and PHP logs are available? From watchdog table? From drush? from both?

1
  • I also doubt that WSOD causes are generally the An unexpected error occurred. Please try again later causes...
    – jorno
    Dec 17, 2023 at 20:17

1 Answer 1

2

The error message is so generic you can't even tell whether it's a PHP or Drupal error, both look the same. The error message is displayed by all production websites when something goes wrong. It doesn't tell any details not to divulge non-public information. You would check the log files if you get a report of such an error in a production environment.

In a dev environment, you usually want to see the error messages on the screen immediately.

For Drupal visit /admin/config/development/logging and set

Error messages to display:

  • All messages, with backtrace information

Set full error messages for a specific IP only

In the comments it was asked what can be done in a production environment to not show error messages to all site visitors while debugging the error. An easy option would be to override the UI config value via settings.php

web/sites/default/settings.php

if ($_SERVER['REMOTE_ADDR'] == '192.168.12.34') {
  $config['system.logging']['error_level'] = 'verbose';
}

and restrict it to your IP so that everybody else is still seeing the generic error message as configured in UI.

Drupal 10.2.x

Updated a site to the just released Drupal 10.2.0 and noticed the error logging has changed. You get now more information from the error logs with the default production settings. See the change record https://www.drupal.org/node/3340781

10
  • But I don't have dev environment; I just have a simple core only website. Should I select All messages, with backtrace information then as well, or will it change the generic error An unexpected error occurred. Please try again later to divulge non-public information?
    – jorno
    Dec 17, 2023 at 20:08
  • Only to debug the error and don't forget to reset the setting afterwards. However, it's not recommended to develop on production sites. Copy the database and the code files to your local hard disk and use a docker-based solution. See drupal.org/docs/develop/local-server-setup/…,
    – 4uk4
    Dec 17, 2023 at 20:24
  • I personally prefer to avoid docker and alike. I misunderstand this: If I choose All messages, with backtrace information where will this data appear? In what file?
    – jorno
    Dec 17, 2023 at 20:28
  • Right on the screen instead of "An unexpected error occurred. Please try again later".
    – 4uk4
    Dec 17, 2023 at 20:28
  • Oh crap, I wonder why Drupal just doesn't have a typical log file accessible from a text editor instead of that...
    – jorno
    Dec 17, 2023 at 20:31

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