From: Aaron Schulz Date: Wed, 13 Mar 2019 16:12:47 +0000 (-0700) Subject: rdbms: make query exceptions include the backtrace when logged X-Git-Tag: 1.34.0-rc.0~2524^2 X-Git-Url: http://git.cyclocoop.org/%22%2C%20generer_url_ecrire%28?a=commitdiff_plain;h=5d6141f172815a3793feb713dab7a32a54d1e808;p=lhc%2Fweb%2Fwiklou.git 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 --- 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" );