Updated: Comment #N

Problem/Motivation

If you trigger a PHP warning too early during Drupal's install (or boot?) process (for example, in file_directory_os_temp, see #2110863: Support open_basedir) then watchdog() will throw an InvalidArgumentException with the message

The service definition "module_handler" does not exist

.

This will bubble up through:
_drupal_log_error()
_drupal_error_handler_real()
_drupal_error_handler()
and eventually cause the user to see #2091501: When install fails: Fatal error: Call to undefined function theme() in install.core.inc on line 954

Proposed resolution

Consider if we can safely and usefully handle the error in the watchdog() function.
If not, then catch and discard the error, as we do for other errors in that function.

Remaining tasks

Decide on approach
Write patch

User interface changes

None

API changes

An undocumented exception is less likely to be thrown.

Comments

ianthomas_uk’s picture

StatusFileSize
new545 bytes

Here is an example patch to trigger the problem. With this applied, I see

Additional uncaught exception thrown while handling exception.
Original

Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service definition "module_handler" does not exist. in Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() (line 875 of /Applications/MAMP/htdocs/drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php).
Additional

Symfony\Component\DependencyInjection\Exception\InvalidArgumentException: The service definition "module_handler" does not exist. in Symfony\Component\DependencyInjection\ContainerBuilder->getDefinition() (line 875 of /Applications/MAMP/htdocs/drupal/core/vendor/symfony/dependency-injection/Symfony/Component/DependencyInjection/ContainerBuilder.php).

(if you see a different error, check #2091501: When install fails: Fatal error: Call to undefined function theme() in install.core.inc on line 954)

ianthomas_uk’s picture

I've attached two patches. Option A is as specific as possible so only catches this known exception. Option B assumes that watchdog should never throw any exceptions, so catches anything that might be thrown while $in_error_state is true. I prefer option B as I don't see why you'd want watchdog() to throw exceptions, but I'm interested in other opinions.

With either of the above patches applied, that error becomes

Fatal error: Exception thrown while logging a system message. Original message: User warning: Example PHP warning in install_begin_request() (line 294 of /Applications/MAMP/htdocs/drupal/core/includes/install.core.inc). in /Applications/MAMP/htdocs/drupal/core/includes/bootstrap.inc on line 1573

ianthomas_uk’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2153401-1-option-b-watchdog-exception.patch, failed testing.

The last submitted patch, 2: 2153401-1-option-b-watchdog-exception.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2153401-1-option-b-watchdog-exception.patch, failed testing.

ianthomas_uk’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: 2153401-1-option-b-watchdog-exception.patch, failed testing.

sun’s picture

I think my patch in #2194111: Error handler throws exception when service container is not (fully) available yet fixes the root cause, which should also resolve this issue?

jhedstrom’s picture

Status: Needs work » Postponed (maintainer needs more info)

Needs confirmation that ##1 resolves the issue.

larowlan’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)