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 ...@@ -1847,8 +1847,21 @@ function _drupal_error_handler($error_level, $message, $filename, $line, $contex
*/ */
function _drupal_exception_handler($exception) { function _drupal_exception_handler($exception) {
require_once DRUPAL_ROOT . '/includes/errors.inc'; require_once DRUPAL_ROOT . '/includes/errors.inc';
// Log the message to the watchdog and return an error page to the user.
_drupal_log_error(_drupal_decode_exception($exception), TRUE); 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() { ...@@ -2690,12 +2703,13 @@ function _drupal_shutdown_function() {
call_user_func_array($callback['callback'], $callback['arguments']); call_user_func_array($callback['callback'], $callback['arguments']);
} }
} }
catch(Exception $exception) { catch (Exception $exception) {
require_once DRUPAL_ROOT . '/includes/errors.inc'; // If we are displaying errors, then do so with no possibility of a further uncaught exception being thrown.
// The theme has already been printed so it doesn't make much sense to use $error_level = variable_get('error_level', ERROR_REPORTING_DISPLAY_ALL);
// drupal_exception_handler() because that would display the maintenaince if ($error_level == ERROR_REPORTING_DISPLAY_ALL || (defined('MAINTENANCE_MODE') && MAINTENANCE_MODE == 'update')) {
// page below the usual page. For now, just print the error for debugging. require_once DRUPAL_ROOT . '/includes/errors.inc';
// @todo: Improve this. print 'Uncaught exception thrown in shutdown function.<br /><br />';
print t('%type: %message in %function (line %line of %file).', _drupal_decode_exception($exception)); print _drupal_render_exception_safe($exception) . '<br /><br />';
}
} }
} }
...@@ -87,7 +87,8 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c ...@@ -87,7 +87,8 @@ function _drupal_error_handler_real($error_level, $message, $filename, $line, $c
* *
* @param $exception * @param $exception
* The exception object that was thrown. * 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) { function _drupal_decode_exception($exception) {
$message = $exception->getMessage(); $message = $exception->getMessage();
...@@ -125,6 +126,18 @@ function _drupal_decode_exception($exception) { ...@@ -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. * Log a PHP error or exception, display an error page in fatal cases.
* *
...@@ -163,13 +176,7 @@ function _drupal_log_error($error, $fatal = FALSE) { ...@@ -163,13 +176,7 @@ function _drupal_log_error($error, $fatal = FALSE) {
$number++; $number++;
} }
try { watchdog('php', '%type: %message in %function (line %line of %file).', $error, $error['severity_level']);
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) { if ($fatal) {
drupal_add_http_header('Status', '500 Service unavailable (with message)'); 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