Adjust error handling to account for the new DatabaseWrapperException.
parent
7ac8d9ac6e
commit
40817bb3cd
|
@ -209,24 +209,27 @@ class ExceptionController {
|
||||||
// FlattenException version of the backtrace.
|
// FlattenException version of the backtrace.
|
||||||
$backtrace[0]['line'] = $exception->getLine();
|
$backtrace[0]['line'] = $exception->getLine();
|
||||||
|
|
||||||
// For PDOException errors, we try to return the initial caller,
|
// For database errors, we try to return the initial caller,
|
||||||
// skipping internal functions of the database layer.
|
// skipping internal functions of the database layer.
|
||||||
if ($exception instanceof PDOException) {
|
if (strpos($exception->getClass(), 'DatabaseExceptionWrapper') !== FALSE) {
|
||||||
|
// A DatabaseExceptionWrapper exception is actually just a courier for
|
||||||
|
// the original PDOException. It's the stack trace from that exception
|
||||||
|
// that we care about.
|
||||||
|
$backtrace = $exception->getPrevious()->getTrace();
|
||||||
|
$backtrace[0]['line'] = $exception->getLine();
|
||||||
|
|
||||||
// The first element in the stack is the call, the second element gives us the caller.
|
// The first element in the stack is the call, the second element gives us the caller.
|
||||||
// We skip calls that occurred in one of the classes of the database layer
|
// We skip calls that occurred in one of the classes of the database layer
|
||||||
// or in one of its global functions.
|
// or in one of its global functions.
|
||||||
$db_functions = array('db_query', 'db_query_range');
|
$db_functions = array('db_query', 'db_query_range');
|
||||||
while (!empty($backtrace[1]) && ($caller = $backtrace[1]) &&
|
while (!empty($backtrace[1]) && ($caller = $backtrace[1]) &&
|
||||||
((isset($caller['class']) && (strpos($caller['class'], 'Query') !== FALSE || strpos($caller['class'], 'Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE)) ||
|
((strpos($caller['namespace'], 'Drupal\Core\Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE)) ||
|
||||||
in_array($caller['function'], $db_functions))) {
|
in_array($caller['function'], $db_functions)) {
|
||||||
// We remove that call.
|
// We remove that call.
|
||||||
array_shift($backtrace);
|
array_shift($backtrace);
|
||||||
}
|
}
|
||||||
if (isset($exception->query_string, $exception->args)) {
|
|
||||||
$message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE);
|
|
||||||
}
|
}
|
||||||
}
|
$caller = $this->getLastCaller($backtrace);
|
||||||
$caller = _drupal_get_last_caller($backtrace);
|
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'%type' => $exception->getClass(),
|
'%type' => $exception->getClass(),
|
||||||
|
|
|
@ -76,7 +76,7 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
|
||||||
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
|
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
|
||||||
);
|
);
|
||||||
$error_pdo_exception = array(
|
$error_pdo_exception = array(
|
||||||
'%type' => 'PDOException',
|
'%type' => 'DatabaseExceptionWrapper',
|
||||||
'!message' => 'SELECT * FROM bananas_are_awesome',
|
'!message' => 'SELECT * FROM bananas_are_awesome',
|
||||||
'%function' => 'error_test_trigger_pdo_exception()',
|
'%function' => 'error_test_trigger_pdo_exception()',
|
||||||
'%line' => 64,
|
'%line' => 64,
|
||||||
|
|
|
@ -3,4 +3,4 @@ description = "Support module for error and exception testing."
|
||||||
package = Testing
|
package = Testing
|
||||||
version = VERSION
|
version = VERSION
|
||||||
core = 8.x
|
core = 8.x
|
||||||
hidden = TRUE
|
hidden = FALSE
|
||||||
|
|
Loading…
Reference in New Issue