Issue #2505315 by stefan.r, dawehner, tim.plunkett, Berdir: Catch PHP7 Throwable objects instead of BaseExceptions in the error handler
parent
4988a81a75
commit
a8f8b33e72
|
@ -679,7 +679,7 @@ function _drupal_error_handler($error_level, $message, $filename, $line, $contex
|
|||
* always fatal: the execution of the script will stop as soon as the exception
|
||||
* handler exits.
|
||||
*
|
||||
* @param \Exception|\BaseException $exception
|
||||
* @param \Exception|\Throwable $exception
|
||||
* The exception object that was thrown.
|
||||
*/
|
||||
function _drupal_exception_handler($exception) {
|
||||
|
@ -689,12 +689,13 @@ function _drupal_exception_handler($exception) {
|
|||
// Log the message to the watchdog and return an error page to the user.
|
||||
_drupal_log_error(Error::decodeException($exception), TRUE);
|
||||
}
|
||||
// PHP 7 introduces BaseExceptions.
|
||||
catch (BaseException $exception2) {
|
||||
_drupal_exception_handler_additional($exception, $exception2);
|
||||
// PHP 7 introduces Throwable, which covers both Error and
|
||||
// Exception throwables.
|
||||
catch (\Throwable $error) {
|
||||
_drupal_exception_handler_additional($exception, $error);
|
||||
}
|
||||
// In order to be compatibile with PHP 5 we also catch regular Exceptions.
|
||||
catch (Exception $exception2) {
|
||||
catch (\Exception $exception2) {
|
||||
_drupal_exception_handler_additional($exception, $exception2);
|
||||
}
|
||||
}
|
||||
|
@ -702,9 +703,9 @@ function _drupal_exception_handler($exception) {
|
|||
/**
|
||||
* Displays any additional errors caught while handling an exception.
|
||||
*
|
||||
* @param \Exception|\BaseException $exception
|
||||
* @param \Exception|\Throwable $exception
|
||||
* The first exception object that was thrown.
|
||||
* @param \Exception|\BaseException $exception
|
||||
* @param \Exception|\Throwable $exception2
|
||||
* The second exception object that was thrown.
|
||||
*/
|
||||
function _drupal_exception_handler_additional($exception, $exception2) {
|
||||
|
@ -1098,12 +1099,13 @@ function _drupal_shutdown_function() {
|
|||
call_user_func_array($callback['callback'], $callback['arguments']);
|
||||
}
|
||||
}
|
||||
// PHP 7 introduces BaseExceptions.
|
||||
catch (BaseException $exception) {
|
||||
_drupal_shutdown_function_handle_exception($exception);
|
||||
// PHP 7 introduces Throwable, which covers both Error and
|
||||
// Exception throwables.
|
||||
catch (\Throwable $error) {
|
||||
_drupal_shutdown_function_handle_exception($error);
|
||||
}
|
||||
// In order to be compatibile with PHP 5 we also catch regular Exceptions.
|
||||
catch (Exception $exception) {
|
||||
catch (\Exception $exception) {
|
||||
_drupal_shutdown_function_handle_exception($exception);
|
||||
}
|
||||
}
|
||||
|
@ -1111,7 +1113,7 @@ function _drupal_shutdown_function() {
|
|||
/**
|
||||
* Displays and logs any errors that may happen during shutdown.
|
||||
*
|
||||
* @param \Exception|\BaseException $exception
|
||||
* @param \Exception|\Throwable $exception
|
||||
* The exception object that was thrown.
|
||||
*
|
||||
* @see _drupal_shutdown_function()
|
||||
|
|
|
@ -33,7 +33,7 @@ class Error {
|
|||
/**
|
||||
* Decodes an exception and retrieves the correct caller.
|
||||
*
|
||||
* @param \Exception|\BaseException $exception
|
||||
* @param \Exception|\Throwable $exception
|
||||
* The exception object that was thrown.
|
||||
*
|
||||
* @return array
|
||||
|
@ -82,7 +82,7 @@ class Error {
|
|||
/**
|
||||
* Renders an exception error message without further exceptions.
|
||||
*
|
||||
* @param \Exception|\BaseException $exception
|
||||
* @param \Exception|\Throwable $exception
|
||||
* The exception object that was thrown.
|
||||
*
|
||||
* @return string
|
||||
|
|
|
@ -52,8 +52,8 @@ class ErrorHandlerTest extends WebTestBase {
|
|||
'!message' => 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 66 and defined',
|
||||
);
|
||||
if (version_compare(PHP_VERSION, '7.0.0-dev') >= 0) {
|
||||
// In PHP 7, instead of a recoverable fatal error we get a TypeException.
|
||||
$fatal_error['%type'] = 'TypeException';
|
||||
// In PHP 7, instead of a recoverable fatal error we get a TypeError.
|
||||
$fatal_error['%type'] = 'TypeError';
|
||||
// The error message also changes in PHP 7.
|
||||
$fatal_error['!message'] = 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in ' . \Drupal::root() . '/core/modules/system/tests/modules/error_test/src/Controller/ErrorTestController.php on line 66';
|
||||
}
|
||||
|
@ -76,9 +76,9 @@ class ErrorHandlerTest extends WebTestBase {
|
|||
|
||||
// Remove the recoverable fatal error from the assertions, it's wanted here.
|
||||
// Ensure that we just remove this one recoverable fatal error (in PHP 7 this
|
||||
// is a TypeException).
|
||||
// is a TypeError).
|
||||
foreach ($this->assertions as $key => $assertion) {
|
||||
if (in_array($assertion['message_group'], ['Recoverable fatal error', 'TypeException']) && strpos($assertion['message'], 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in') !== FALSE) {
|
||||
if (in_array($assertion['message_group'], ['Recoverable fatal error', 'TypeError']) && strpos($assertion['message'], 'Argument 1 passed to Drupal\error_test\Controller\ErrorTestController::Drupal\error_test\Controller\{closure}() must be of the type array, string given, called in') !== FALSE) {
|
||||
unset($this->assertions[$key]);
|
||||
$this->deleteAssert($assertion['message_id']);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue