diff --git a/core/includes/bootstrap.inc b/core/includes/bootstrap.inc index 107ca9a..7fd74ec 100644 --- a/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2210,10 +2210,6 @@ function _drupal_exception_handler($exception) { * Sets up the script environment and loads settings.php. */ function _drupal_bootstrap_configuration() { - // Set the Drupal custom error handler. - set_error_handler('_drupal_error_handler'); - set_exception_handler('_drupal_exception_handler'); - drupal_environment_initialize(); // Start a page timer: timer_start('page'); @@ -2228,6 +2224,11 @@ function _drupal_bootstrap_configuration() { // Load the procedural configuration system helper functions. require_once DRUPAL_ROOT . '/core/includes/config.inc'; + + // Set the Drupal custom error handler. (requires config()) + set_error_handler('_drupal_error_handler'); + set_exception_handler('_drupal_exception_handler'); + // Redirect the user to the installation script if Drupal has not been // installed yet (i.e., if no $databases array has been defined in the // settings.php file) and we are not already installing. diff --git a/core/includes/errors.inc b/core/includes/errors.inc index 5fc4b7d..5511262 100644 --- a/core/includes/errors.inc +++ b/core/includes/errors.inc @@ -153,14 +153,46 @@ function _drupal_render_exception_safe($exception) { * TRUE if an error should be displayed. */ function error_displayable($error = NULL) { - $error_level = config('system.logging')->get('error_level'); - $updating = (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update'); - $all_errors_displayed = ($error_level == ERROR_REPORTING_DISPLAY_ALL) || - ($error_level == ERROR_REPORTING_DISPLAY_VERBOSE); - $error_needs_display = ($error_level == ERROR_REPORTING_DISPLAY_SOME && - isset($error) && $error['%type'] != 'Notice' && $error['%type'] != 'Strict warning'); + global $conf; - return ($updating || $all_errors_displayed || $error_needs_display); + // For maintenance scripts, all errors are displayed. + if (defined('MAINTENANCE_MODE')) { + return TRUE; + } + // The current bootstrap situation and availability of configuration system + // services is unknown, so we take extra care in trying to retrieve the + // configured error_level value. + try { + $container = drupal_container(); + if ($container) { + // If there is a service container, any of the following calls to get() + // methods may throw an exception, but there won't be a fatal error, since + // we catch it. + $error_level = $container->get('config.factory')->get('system.logging')->get('error_level'); + } + } + catch (\Exception $e) { + // In order to additionally guard against a configured but bogus NULL or + // empty value, we unconditionally apply the fallback logic below. + } + // Try fallback values if the config object does not exist or cannot be loaded. + if (empty($error_level)) { + // Check whether settings.php defines a value. + if (isset($conf['system.logging']['error_level'])) { + $error_level = $conf['system.logging']['error_level']; + } + // Otherwise, default to ERROR_REPORTING_DISPLAY_ALL. + else { + $error_level = ERROR_REPORTING_DISPLAY_ALL; + } + } + if ($error_level == ERROR_REPORTING_DISPLAY_ALL || $error_level == ERROR_REPORTING_DISPLAY_VERBOSE) { + return TRUE; + } + if ($error_level == ERROR_REPORTING_DISPLAY_SOME) { + return isset($error) && $error['%type'] != 'Notice' && $error['%type'] != 'Strict warning'; + } + return FALSE; } /**