Commit 1e25da7e authored by webchick's avatar webchick

#742246 by jbrown: Fixed Uncaught exceptions thrown in the exception handler...

#742246 by jbrown: Fixed Uncaught exceptions thrown in the exception handler prevent error reporting.
parent 807704e1
......@@ -1847,8 +1847,21 @@ function _drupal_error_handler($error_level, $message, $filename, $line, $contex
*/
function _drupal_exception_handler($exception) {
require_once DRUPAL_ROOT . '/includes/errors.inc';
try {
// Log the message to the watchdog and return an error page to the user.
_drupal_log_error(_drupal_decode_exception($exception), TRUE);
}
catch (Exception $exception2) {
// Another uncaught exception was thrown while handling the first one.
// If we are displaying errors, then do so with no possibility of a further uncaught exception being thrown.
$error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL);
if ($error_level == ERROR_REPORTING_DISPLAY_ALL || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) {
print 'Additional uncaught exception thrown while handling exception.<br /><br />';
print '<b>Original</b><br />' . _drupal_render_exception_safe($exception) . '<br /><br />';
print '<b>Additional</b><br />' . _drupal_render_exception_safe($exception2) . '<br /><br />';
}
}
}
/**
......@@ -2690,12 +2703,13 @@ function _drupal_shutdown_function() {
call_user_func_array($callback['callback'], $callback['arguments']);
}
}
catch(Exception $exception) {
catch (Exception $exception) {
// If we are displaying errors, then do so with no possibility of a further uncaught exception being thrown.
$error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL);
if ($error_level == ERROR_REPORTING_DISPLAY_ALL || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) {
require_once DRUPAL_ROOT . '/includes/errors.inc';
// The theme has already been printed so it doesn't make much sense to use
// drupal_exception_handler() because that would display the maintenaince
// page below the usual page. For now, just print the error for debugging.
// @todo: Improve this.
print t('%type: %message in %function (line %line of %file).', _drupal_decode_exception($exception));
print 'Uncaught exception thrown in shutdown function.<br /><br />';
print _drupal_render_exception_safe($exception) . '<br /><br />';
}
}
}
......@@ -87,7 +87,8 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c
*
* @param $exception
* The exception object that was thrown.
* @return An error in the format expected by _drupal_log_error().
* @return
* An error in the format expected by _drupal_log_error().
*/
function _drupal_decode_exception($exception) {
$message = $exception->getMessage();
......@@ -125,6 +126,18 @@ function _drupal_decode_exception($exception) {
);
}
/**
* Render an error message for an exception without any possibility of a further exception occuring.
*
* @param $exception
* The exception object that was thrown.
* @return
* An error message.
*/
function _drupal_render_exception_safe($exception) {
return strtr('%type: %message in %function (line %line of %file).', _drupal_decode_exception($exception));
}
/**
* Log a PHP error or exception, display an error page in fatal cases.
*
......@@ -163,13 +176,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
$number++;
}
try {
watchdog('php', '%type: %message in %function (line %line of %file).', $error, $error['severity_level']);
}
catch (Exception $e) {
// Ignore any additional watchdog exception, as that probably means
// that the database was not initialized correctly.
}
if ($fatal) {
drupal_add_http_header('Status', '500 Service unavailable (with message)');
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment