[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Exception cleanups for LoadBalancer

2016-09-14 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged.

Change subject: Exception cleanups for LoadBalancer
..


Exception cleanups for LoadBalancer

* Make the error message itself be dumb/raw.
* Make the exception exposer show the same GUI message.
* Remove overzelous wgLang check in MWExceptionRenderer.

Change-Id: If3b3cc785ea3080e4975efe33b3c2cf304d6
---
M autoload.php
M includes/db/loadbalancer/LoadBalancer.php
M includes/exception/MWExceptionRenderer.php
M includes/libs/rdbms/exception/DBError.php
4 files changed, 41 insertions(+), 11 deletions(-)

Approvals:
  Krinkle: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/autoload.php b/autoload.php
index 66736b3..b9fd6bd 100644
--- a/autoload.php
+++ b/autoload.php
@@ -311,6 +311,7 @@
'DBReplicationWaitError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBError.php',
'DBSiteStore' => __DIR__ . '/includes/site/DBSiteStore.php',
'DBTransactionError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBError.php',
+   'DBTransactionSizeError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBError.php',
'DBUnexpectedError' => __DIR__ . 
'/includes/libs/rdbms/exception/DBError.php',
'DataUpdate' => __DIR__ . '/includes/deferred/DataUpdate.php',
'Database' => __DIR__ . '/includes/db/Database.php',
diff --git a/includes/db/loadbalancer/LoadBalancer.php 
b/includes/db/loadbalancer/LoadBalancer.php
index 841231b..b5c6f98 100644
--- a/includes/db/loadbalancer/LoadBalancer.php
+++ b/includes/db/loadbalancer/LoadBalancer.php
@@ -784,7 +784,8 @@
}
 
if ( !is_array( $server ) ) {
-   throw new InvalidArgumentException( 'You must update 
your load-balancing configuration. ' .
+   throw new InvalidArgumentException(
+   'You must update your load-balancing 
configuration. ' .
'See DefaultSettings.php entry for 
$wgDBservers.' );
}
 
@@ -1034,10 +1035,10 @@
// If this fails, then all DB transactions will be 
rollback back together.
$time = $conn->pendingWriteQueryDuration( 
$conn::ESTIMATE_DB_APPLY );
if ( $limit > 0 && $time > $limit ) {
-   throw new DBTransactionError(
+   throw new DBTransactionSizeError(
$conn,
"Transaction spent $time second(s) in 
writes, exceeding the $limit limit.",
-   wfMessage( 
'transaction-duration-limit-exceeded', $time, $limit )->text()
+   [ $time, $limit ]
);
}
// If a connection sits idle while slow queries execute 
on another, that connection
diff --git a/includes/exception/MWExceptionRenderer.php 
b/includes/exception/MWExceptionRenderer.php
index f455191..58b4ac7 100644
--- a/includes/exception/MWExceptionRenderer.php
+++ b/includes/exception/MWExceptionRenderer.php
@@ -134,15 +134,13 @@
 */
private static function useOutputPage( Exception $e ) {
// Can the extension use the Message class/wfMessage to get 
i18n-ed messages?
-   $useMessageCache = ( $GLOBALS['wgLang'] instanceof Language );
foreach ( $e->getTrace() as $frame ) {
if ( isset( $frame['class'] ) && $frame['class'] === 
'LocalisationCache' ) {
-   $useMessageCache = false;
+   return false;
}
}
 
return (
-   $useMessageCache &&
!empty( $GLOBALS['wgFullyInitialised'] ) &&
!empty( $GLOBALS['wgOut'] ) &&
!defined( 'MEDIAWIKI_INSTALL' )
@@ -172,6 +170,10 @@
if ( $hookResult ) {
$wgOut->addHTML( $hookResult );
} else {
+   // Show any custom GUI message before the 
details
+   if ( $e instanceof MessageSpecifier ) {
+   $wgOut->addHtml( 
Message::newFromSpecifier( $e )->escaped() );
+   }
$wgOut->addHTML( self::getHTML( $e ) );
}
 
@@ -209,14 +211,14 @@
 */
private static function getHTML( Exception $e ) {
if ( self::showBackTrace( $e ) ) {
-   return '' .
+   $html = "" .
nl2br( htmlspecialchars( 
MWExceptionHandler::getLogMessage( $e ) ) ) .
'Backtrace:' .
  

[MediaWiki-commits] [Gerrit] mediawiki/core[master]: Exception cleanups for LoadBalancer

2016-09-14 Thread Aaron Schulz (Code Review)
Aaron Schulz has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/310511

Change subject: Exception cleanups for LoadBalancer
..

Exception cleanups for LoadBalancer

* Make the error message itself be dumb/raw.
* Make the exception exposer show the same GUI message.
* Remove overzelous wgLang check in MWExceptionExposer.

Change-Id: If3b3cc785ea3080e4975efe33b3c2cf304d6
---
M autoload.php
M includes/db/DatabaseError.php
M includes/db/loadbalancer/LoadBalancer.php
M includes/exception/MWExceptionExposer.php
4 files changed, 41 insertions(+), 11 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/11/310511/1

diff --git a/autoload.php b/autoload.php
index b4860c9..f71e9f4 100644
--- a/autoload.php
+++ b/autoload.php
@@ -311,6 +311,7 @@
'DBReplicationWaitError' => __DIR__ . '/includes/db/DatabaseError.php',
'DBSiteStore' => __DIR__ . '/includes/site/DBSiteStore.php',
'DBTransactionError' => __DIR__ . '/includes/db/DatabaseError.php',
+   'DBTransactionSizeError' => __DIR__ . '/includes/db/DatabaseError.php',
'DBUnexpectedError' => __DIR__ . '/includes/db/DatabaseError.php',
'DataUpdate' => __DIR__ . '/includes/deferred/DataUpdate.php',
'Database' => __DIR__ . '/includes/db/Database.php',
diff --git a/includes/db/DatabaseError.php b/includes/db/DatabaseError.php
index 2242c5a..38887cf 100644
--- a/includes/db/DatabaseError.php
+++ b/includes/db/DatabaseError.php
@@ -26,7 +26,7 @@
  * @ingroup Database
  */
 class DBError extends Exception {
-   /** @var IDatabase */
+   /** @var IDatabase|null */
public $db;
 
/**
@@ -47,7 +47,22 @@
  * @ingroup Database
  * @since 1.23
  */
-class DBExpectedError extends DBError {
+class DBExpectedError extends DBError implements MessageSpecifier {
+   /** @var string[] Message parameters */
+   protected $params;
+
+   function __construct( IDatabase $db = null, $error, array $params = [] 
) {
+   parent::__construct( $db, $error );
+   $this->params = $params;
+   }
+
+   public function getKey() {
+   return 'databaseerror-text';
+   }
+
+   public function getParams() {
+   return $this->params;
+   }
 }
 
 /**
@@ -124,6 +139,15 @@
 }
 
 /**
+ * @ingroup Database
+ */
+class DBTransactionSizeError extends DBTransactionError {
+   function getKey() {
+   return 'transaction-duration-limit-exceeded';
+   }
+}
+
+/**
  * Exception class for replica DB wait timeouts
  * @ingroup Database
  */
diff --git a/includes/db/loadbalancer/LoadBalancer.php 
b/includes/db/loadbalancer/LoadBalancer.php
index ce1899f..9456e66 100644
--- a/includes/db/loadbalancer/LoadBalancer.php
+++ b/includes/db/loadbalancer/LoadBalancer.php
@@ -785,7 +785,8 @@
}
 
if ( !is_array( $server ) ) {
-   throw new InvalidArgumentException( 'You must update 
your load-balancing configuration. ' .
+   throw new InvalidArgumentException(
+   'You must update your load-balancing 
configuration. ' .
'See DefaultSettings.php entry for 
$wgDBservers.' );
}
 
@@ -1035,10 +1036,10 @@
// If this fails, then all DB transactions will be 
rollback back together.
$time = $conn->pendingWriteQueryDuration( 
$conn::ESTIMATE_DB_APPLY );
if ( $limit > 0 && $time > $limit ) {
-   throw new DBTransactionError(
+   throw new DBTransactionSizeError(
$conn,
"Transaction spent $time second(s) in 
writes, exceeding the $limit limit.",
-   wfMessage( 
'transaction-duration-limit-exceeded', $time, $limit )->text()
+   [ $time, $limit ]
);
}
// If a connection sits idle while slow queries execute 
on another, that connection
diff --git a/includes/exception/MWExceptionExposer.php 
b/includes/exception/MWExceptionExposer.php
index 4560977..63feda3 100644
--- a/includes/exception/MWExceptionExposer.php
+++ b/includes/exception/MWExceptionExposer.php
@@ -134,15 +134,13 @@
 */
private static function useOutputPage( Exception $e ) {
// Can the extension use the Message class/wfMessage to get 
i18n-ed messages?
-   $useMessageCache = ( $GLOBALS['wgLang'] instanceof Language );
foreach ( $e->getTrace() as $frame ) {
if ( isset( $frame['class'] ) && $frame['class'] === 
'LocalisationCache' ) {
-   $useMessageCache = false;
+