From 40817bb3cde9a85505b850a2618598bc2b9d3149 Mon Sep 17 00:00:00 2001 From: Larry Garfield Date: Wed, 25 Apr 2012 18:23:06 -0500 Subject: [PATCH] Adjust error handling to account for the new DatabaseWrapperException. --- core/lib/Drupal/Core/ExceptionController.php | 19 +++++++++++-------- core/modules/system/tests/error.test | 2 +- .../tests/modules/error_test/error_test.info | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/lib/Drupal/Core/ExceptionController.php b/core/lib/Drupal/Core/ExceptionController.php index 480d76b0474..69e9dd5afa4 100644 --- a/core/lib/Drupal/Core/ExceptionController.php +++ b/core/lib/Drupal/Core/ExceptionController.php @@ -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(), diff --git a/core/modules/system/tests/error.test b/core/modules/system/tests/error.test index e87ce67296d..e05cef43eb5 100644 --- a/core/modules/system/tests/error.test +++ b/core/modules/system/tests/error.test @@ -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, diff --git a/core/modules/system/tests/modules/error_test/error_test.info b/core/modules/system/tests/modules/error_test/error_test.info index d5db3ee392f..d00075de2d8 100644 --- a/core/modules/system/tests/modules/error_test/error_test.info +++ b/core/modules/system/tests/modules/error_test/error_test.info @@ -3,4 +3,4 @@ description = "Support module for error and exception testing." package = Testing version = VERSION core = 8.x -hidden = TRUE +hidden = FALSE