From 5d6141f172815a3793feb713dab7a32a54d1e808 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 13 Mar 2019 09:12:47 -0700 Subject: [PATCH] rdbms: make query exceptions include the backtrace when logged Previously, the corresponding Exception channel entry was relied on for the backtrace, though there might not always be one. Change-Id: I4a3b0fec0beaec1ebfe71be3850aa353cd37d562 --- includes/libs/rdbms/database/Database.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/includes/libs/rdbms/database/Database.php b/includes/libs/rdbms/database/Database.php index 49b2792210..6d80f02845 100644 --- a/includes/libs/rdbms/database/Database.php +++ b/includes/libs/rdbms/database/Database.php @@ -1236,7 +1236,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware # option is ROLLBACK, since the snapshots would have been released. $this->trxStatus = self::STATUS_TRX_ERROR; $this->trxStatusCause = - $this->makeQueryException( $lastError, $lastErrno, $sql, $fname ); + $this->getQueryExceptionAndLog( $lastError, $lastErrno, $sql, $fname ); $tempIgnore = false; // cannot recover $this->trxStatusIgnoredCause = null; } @@ -1489,7 +1489,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware if ( $tempIgnore ) { $this->queryLogger->debug( "SQL ERROR (ignored): $error\n" ); } else { - $exception = $this->makeQueryException( $error, $errno, $sql, $fname ); + $exception = $this->getQueryExceptionAndLog( $error, $errno, $sql, $fname ); throw $exception; } @@ -1502,7 +1502,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware * @param string $fname * @return DBError */ - private function makeQueryException( $error, $errno, $sql, $fname ) { + private function getQueryExceptionAndLog( $error, $errno, $sql, $fname ) { $sql1line = mb_substr( str_replace( "\n", "\\n", $sql ), 0, 5 * 1024 ); $this->queryLogger->error( "{fname}\t{db_server}\t{errno}\t{error}\t{sql1line}", @@ -1512,6 +1512,7 @@ abstract class Database implements IDatabase, IMaintainableDatabase, LoggerAware 'error' => $error, 'sql1line' => $sql1line, 'fname' => $fname, + 'trace' => ( new RuntimeException() )->getTraceAsString() ] ) ); $this->queryLogger->debug( "SQL ERROR: " . $error . "\n" ); -- 2.20.1