Updated: Comment #N

Problem/Motivation

The installation process sometimes fails with the error message

"Fatal error: Call to undefined function theme() in xxx/core/includes/install.core.inc on line 1009."

The install_drupal function tries to catch exceptions thrown by install_begin_request using install_display_output, however install_display_output returns a themed page, and the theme system is only loaded during install_begin_request. Therefore, if an exception is thrown too soon, the user will get the above error message (triggered on the penultimate line of install_display_output).

This was spotted while working on #2110863: Support open_basedir amoung other instances.

Proposed resolution

Check the theming system is ready before using it and/or have another error handler ready to handle an error thrown by the theming system.

Remaining tasks

Decide on approach
Write patch

User interface changes

None

API changes

None

Files: 
CommentFileSizeAuthor
#4 2091501-4-undefined-function-theme.patch850 bytesianthomas_uk
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Unable to apply patch 2091501-4-undefined-function-theme.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]
#4 2091501-4-example-exception-do-not-test.diff541 bytesianthomas_uk

Comments

Alan D.’s picture

I was easily able to replicate with an existing settings.php file that contained a reference to an existing database that was empty.

Removing the file allowed installation to get to the first page of the install successfully.
Removing the $databases['default']['default'] but keeping the rest of the settings.php file as is, gave an "Drupal already installed" message (file was from a post Drupal 8 alpha 2 install from memory).

ianthomas_uk’s picture

Issue summary:View changes
Priority:Normal» Major
Related issues:+#2110863: Support open_basedir

Updating summary using the template and a more technical description of what is happening.

Original summary

When the install of Drupal 8 fails it (might) fail(s) with the message:

Fatal error: Call to undefined function theme() in drupal\core\includes\install.core.inc on line 954

There are other issues that do mention this error message, but they focus on eliminating a specific case that lead to the install procedure to fail. This issue should make sure that the install fails with a proper message to the user (the message that probably was themed when this error occurs) not with this fatal.

Note: in my case it was an already existing settings.php, a situation that before, IIRC, was handled with a correct message.

Alan D.’s picture

From #2110863-9: Support open_basedir

If you enable open_basedir, this patch gets the install process past the initial open_basedir errors, but after the database is created, before it starts the main install it now throws "Fatal error: Call to undefined function theme() in xxx/core/includes/install.core.inc on line 992."

Note that in my case open_basedir was not set. There may be multiple entry points to getting this same error.

ianthomas_uk’s picture

Status:Active» Needs review
StatusFileSize
new541 bytes
new850 bytes
FAILED: [[SimpleTest]]: [PHP 5.4 MySQL] Unable to apply patch 2091501-4-undefined-function-theme.patch. Unable to apply patch. See the log in the details link for more information.
[ View ]

Here's a patch that will just rethrow the exception instead of attempting to display a nicely themed page if that's not going to possible.

Instead of

"Fatal error: Call to undefined function theme() in xxx/core/includes/install.core.inc on line 1009."

the user will see

Fatal error: Uncaught exception 'Exception' with message '[exception message]' in xxx/core/includes/install.core.inc:257 Stack trace: #0 xxx/core/includes/install.core.inc(92): install_begin_request(Array) #1 xxx/core/install.php(50): install_drupal() #2 {main} thrown in xxx/core/includes/install.core.inc on line 257

Hopefully the exception message will help them solve their problem, but at the very least it will lead them to a better place to start debugging. I've also uploaded a patch to throw an exception that would trigger this problem, for review purposes.

sun’s picture

Please note that #2176105: Installer catches exceptions and manually re-prints them; does not use error/exception handler fixes the error/exception handler for the installer, which removes the code in question here.

xjm’s picture

Status:Needs review» Needs work

The last submitted patch, 4: 2091501-4-undefined-function-theme.patch, failed testing.

Berdir’s picture

Status:Needs work» Closed (duplicate)

Looking at the code, I think this has been refactored elsewhere so that this no longer happens.