Index: simpletest.function.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/simpletest/Attic/simpletest.function.inc,v retrieving revision 1.1.2.2 diff -u -r1.1.2.2 simpletest.function.inc --- simpletest.function.inc 23 Apr 2009 05:39:51 -0000 1.1.2.2 +++ simpletest.function.inc 28 May 2009 16:05:04 -0000 @@ -125,9 +125,13 @@ * TRUE if the error is fatal. */ function _drupal_log_error($error, $fatal = FALSE) { - // Initialize a maintenance theme early if the boostrap was not complete. + // Drupal 6, hack to determine if a full bootstrap has been performed. + $bootstrap_full = function_exists('init_theme'); + + // Initialize a maintenance theme if the boostrap was not complete. // Do it early because drupal_set_message() triggers an init_theme(). - if ($fatal && (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL)) { +// if ($fatal && (drupal_get_bootstrap_phase() != DRUPAL_BOOTSTRAP_FULL)) { + if ($fatal && !$bootstrap_full) { unset($GLOBALS['theme']); if (!defined('MAINTENANCE_MODE')) { define('MAINTENANCE_MODE', 'error'); @@ -152,34 +156,41 @@ $number++; } - // Force display of error messages in update.php or if the proper error - // reporting level is set. - $error_level = variable_get('error_level', 2); - if ($error_level == 2 || ($error_level == 1 && $error['%type'] != 'Notice') || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) { - drupal_set_message(t('%type: %message in %function (line %line of %file).', $error), 'error'); - } - try { watchdog('php', '%type: %message in %function (line %line of %file).', $error, WATCHDOG_ERROR); } catch (Exception $e) { - $new_error = _drupal_decode_exception($e); - drupal_set_message(t('%type: %message in %function (line %line of %file).', $new_error), 'error'); + // Ignore any additional watchdog exception, as that probably means + // that the database was not initialized correctly. } if ($fatal) { - drupal_set_header('503 Service unavailable'); - drupal_set_title(t('Error')); - if (!defined('MAINTENANCE_MODE') && drupal_get_bootstrap_phase() == DRUPAL_BOOTSTRAP_FULL) { - // To conserve CPU and bandwidth, omit the blocks. - $page = drupal_get_page(t('The website encountered an unexpected error. Please try again later.')); - $page['#show_blocks'] = FALSE; - print drupal_render_page($page); + drupal_set_header($_SERVER['SERVER_PROTOCOL'] . ' 500 Service unavailable (with message)'); + } + + if (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { + if ($fatal) { + // When called from JavaScript, simply output the error message. + print t('%type: %message in %function (line %line of %file).', $error); + exit; } - else { + } + else { + // Display the message if the current error reporting level allows this type + // of message to be displayed, and unconditionnaly in update.php. + $error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL); + $display_error = $error_level == ERROR_REPORTING_DISPLAY_ALL || ($error_level == ERROR_REPORTING_DISPLAY_SOME && $error['%type'] != 'Notice'); + if ($display_error || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) { + drupal_set_message(t('%type: %message in %function (line %line of %file).', $error), 'error'); + } + + if ($fatal) { + drupal_set_title(t('Error')); + // We fallback to a maintenance page at this point, because the page generation + // itself can generate errors. print theme('maintenance_page', t('The website encountered an unexpected error. Please try again later.'), FALSE); + exit; } - exit; } }