Adjust error handling to account for the new DatabaseWrapperException.

8.0.x
Larry Garfield 2012-04-25 18:23:06 -05:00
parent 7ac8d9ac6e
commit 40817bb3cd
3 changed files with 13 additions and 10 deletions

View File

@ -209,24 +209,27 @@ class ExceptionController {
// FlattenException version of the backtrace.
$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.
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.
// We skip calls that occurred in one of the classes of the database layer
// or in one of its global functions.
$db_functions = array('db_query', 'db_query_range');
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)) ||
in_array($caller['function'], $db_functions))) {
((strpos($caller['namespace'], 'Drupal\Core\Database') !== FALSE || strpos($caller['class'], 'PDO') !== FALSE)) ||
in_array($caller['function'], $db_functions)) {
// We remove that call.
array_shift($backtrace);
}
if (isset($exception->query_string, $exception->args)) {
$message .= ": " . $exception->query_string . "; " . print_r($exception->args, TRUE);
}
}
$caller = _drupal_get_last_caller($backtrace);
$caller = $this->getLastCaller($backtrace);
return array(
'%type' => $exception->getClass(),

View File

@ -76,7 +76,7 @@ class DrupalErrorHandlerUnitTest extends DrupalWebTestCase {
'%file' => drupal_get_path('module', 'error_test') . '/error_test.module',
);
$error_pdo_exception = array(
'%type' => 'PDOException',
'%type' => 'DatabaseExceptionWrapper',
'!message' => 'SELECT * FROM bananas_are_awesome',
'%function' => 'error_test_trigger_pdo_exception()',
'%line' => 64,

View File

@ -3,4 +3,4 @@ description = "Support module for error and exception testing."
package = Testing
version = VERSION
core = 8.x
hidden = TRUE
hidden = FALSE