Replace some MWExceptions with natives ones in /db
authorAaron Schulz <aschulz@wikimedia.org>
Wed, 14 Sep 2016 02:38:19 +0000 (19:38 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Wed, 14 Sep 2016 08:50:33 +0000 (01:50 -0700)
Change-Id: I94532d09216926d401e94c61acd60fdc6241a2a0

includes/db/CloneDatabase.php
includes/db/Database.php
includes/db/DatabaseMssql.php
includes/db/DatabaseOracle.php
includes/db/DatabaseSqlite.php
includes/db/loadbalancer/LBFactoryMulti.php
includes/db/loadbalancer/LBFactorySimple.php
includes/db/loadbalancer/LoadBalancer.php

index cab9438..97d59d8 100644 (file)
@@ -76,7 +76,7 @@ class CloneDatabase {
                        if ( $wgSharedDB && in_array( $tbl, $wgSharedTables, true ) ) {
                                // Shared tables don't work properly when cloning due to
                                // how prefixes are handled (bug 65654)
-                               throw new MWException( "Cannot clone shared table $tbl." );
+                               throw new RuntimeException( "Cannot clone shared table $tbl." );
                        }
                        # Clean up from previous aborted run.  So that table escaping
                        # works correctly across DB engines, we need to change the pre-
@@ -93,7 +93,7 @@ class CloneDatabase {
                        ) {
                                if ( $oldTableName === $newTableName ) {
                                        // Last ditch check to avoid data loss
-                                       throw new MWException( "Not dropping new table, as '$newTableName'"
+                                       throw new LogicException( "Not dropping new table, as '$newTableName'"
                                                . " is name of both the old and the new table." );
                                }
                                $this->db->dropTable( $tbl, __METHOD__ );
index b044e23..109dbfe 100644 (file)
@@ -340,8 +340,8 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
                                if ( in_array( $p['driver'], $possibleDrivers ) ) {
                                        $driver = $p['driver'];
                                } else {
-                                       throw new MWException( __METHOD__ .
-                                               " cannot construct Database with type '$dbType' and driver '{$p['driver']}'" );
+                                       throw new InvalidArgumentException( __METHOD__ .
+                                               " type '$dbType' does not support driver '{$p['driver']}'" );
                                }
                        } else {
                                foreach ( $possibleDrivers as $posDriver ) {
@@ -740,7 +740,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
         * not restored on unserialize.
         */
        public function __sleep() {
-               throw new MWException( 'Database serialization may cause problems, since ' .
+               throw new RuntimeException( 'Database serialization may cause problems, since ' .
                        'the connection is not restored on wakeup.' );
        }
 
@@ -807,7 +807,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
                        $closed = $this->closeConnection();
                        $this->mConn = false;
                } elseif ( $this->mTrxIdleCallbacks || $this->mTrxEndCallbacks ) { // sanity
-                       throw new MWException( "Transaction callbacks still pending." );
+                       throw new RuntimeException( "Transaction callbacks still pending." );
                } else {
                        $closed = true;
                }
@@ -1736,7 +1736,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
                                        unset( $value[$nullKey] );
                                }
                                if ( count( $value ) == 0 && !$includeNull ) {
-                                       throw new MWException( __METHOD__ . ": empty input for field $field" );
+                                       throw new InvalidArgumentException( __METHOD__ . ": empty input for field $field" );
                                } elseif ( count( $value ) == 0 ) {
                                        // only check if $field is null
                                        $list .= "$field IS NULL";
@@ -3132,12 +3132,12 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
        public function duplicateTableStructure( $oldName, $newName, $temporary = false,
                $fname = __METHOD__
        ) {
-               throw new MWException(
+               throw new RuntimeException(
                        'DatabaseBase::duplicateTableStructure is not implemented in descendant class' );
        }
 
        function listTables( $prefix = null, $fname = __METHOD__ ) {
-               throw new MWException( 'DatabaseBase::listTables is not implemented in descendant class' );
+               throw new RuntimeException( 'DatabaseBase::listTables is not implemented in descendant class' );
        }
 
        /**
@@ -3161,7 +3161,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
         * @since 1.22
         */
        public function listViews( $prefix = null, $fname = __METHOD__ ) {
-               throw new MWException( 'DatabaseBase::listViews is not implemented in descendant class' );
+               throw new RuntimeException( 'DatabaseBase::listViews is not implemented in descendant class' );
        }
 
        /**
@@ -3173,7 +3173,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
         * @since 1.22
         */
        public function isView( $name ) {
-               throw new MWException( 'DatabaseBase::isView is not implemented in descendant class' );
+               throw new RuntimeException( 'DatabaseBase::isView is not implemented in descendant class' );
        }
 
        public function timestamp( $ts = 0 ) {
@@ -3368,7 +3368,7 @@ abstract class DatabaseBase implements IDatabase, LoggerAwareInterface {
                MediaWiki\restoreWarnings();
 
                if ( false === $fp ) {
-                       throw new MWException( "Could not open \"{$filename}\".\n" );
+                       throw new RuntimeException( "Could not open \"{$filename}\".\n" );
                }
 
                if ( !$fname ) {
index f8770d2..269a248 100644 (file)
@@ -1080,17 +1080,17 @@ class DatabaseMssql extends Database {
         */
        private function escapeIdentifier( $identifier ) {
                if ( strlen( $identifier ) == 0 ) {
-                       throw new MWException( "An identifier must not be empty" );
+                       throw new InvalidArgumentException( "An identifier must not be empty" );
                }
                if ( strlen( $identifier ) > 128 ) {
-                       throw new MWException( "The identifier '$identifier' is too long (max. 128)" );
+                       throw new InvalidArgumentException( "The identifier '$identifier' is too long (max. 128)" );
                }
                if ( ( strpos( $identifier, '[' ) !== false )
                        || ( strpos( $identifier, ']' ) !== false )
                ) {
                        // It may be allowed if you quoted with double quotation marks, but
                        // that would break if QUOTED_IDENTIFIER is OFF
-                       throw new MWException( "Square brackets are not allowed in '$identifier'" );
+                       throw new InvalidArgumentException( "Square brackets are not allowed in '$identifier'" );
                }
 
                return "[$identifier]";
index ebeb3a6..f401058 100644 (file)
@@ -369,7 +369,7 @@ class DatabaseOracle extends Database {
        protected function doQuery( $sql ) {
                wfDebug( "SQL: [$sql]\n" );
                if ( !StringUtils::isUtf8( $sql ) ) {
-                       throw new MWException( "SQL encoding is invalid\n$sql" );
+                       throw new InvalidArgumentException( "SQL encoding is invalid\n$sql" );
                }
 
                // handle some oracle specifics
index e6401b3..ef08ab0 100644 (file)
@@ -962,7 +962,7 @@ class DatabaseSqlite extends Database {
                        $this->addQuotes( $oldName ) . " AND type='table'", $fname );
                $obj = $this->fetchObject( $res );
                if ( !$obj ) {
-                       throw new MWException( "Couldn't retrieve structure for table $oldName" );
+                       throw new RuntimeException( "Couldn't retrieve structure for table $oldName" );
                }
                $sql = $obj->sql;
                $sql = preg_replace(
index d486e13..dd7737b 100644 (file)
@@ -178,7 +178,7 @@ class LBFactoryMulti extends LBFactory {
 
                foreach ( $required as $key ) {
                        if ( !isset( $conf[$key] ) ) {
-                               throw new MWException( __CLASS__ . ": $key is required in configuration" );
+                               throw new InvalidArgumentException( __CLASS__ . ": $key is required in configuration" );
                        }
                        $this->$key = $conf[$key];
                }
@@ -269,7 +269,7 @@ class LBFactoryMulti extends LBFactory {
         */
        protected function newExternalLB( $cluster, $wiki = false ) {
                if ( !isset( $this->externalLoads[$cluster] ) ) {
-                       throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
+                       throw new InvalidArgumentException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
                }
                $template = $this->serverTemplate;
                if ( isset( $this->externalTemplateOverrides ) ) {
index 69c4abb..d8590b7 100644 (file)
@@ -110,7 +110,7 @@ class LBFactorySimple extends LBFactory {
        protected function newExternalLB( $cluster, $wiki = false ) {
                global $wgExternalServers;
                if ( !isset( $wgExternalServers[$cluster] ) ) {
-                       throw new MWException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
+                       throw new InvalidArgumentException( __METHOD__ . ": Unknown cluster \"$cluster\"" );
                }
 
                return $this->newLoadBalancer( $wgExternalServers[$cluster] );
index 5e7743a..687317c 100644 (file)
@@ -261,7 +261,7 @@ class LoadBalancer implements ILoadBalancer {
                }
 
                if ( !count( $nonErrorLoads ) ) {
-                       throw new MWException( "Empty server array given to LoadBalancer" );
+                       throw new InvalidArgumentException( "Empty server array given to LoadBalancer" );
                }
 
                # Scale the configured load ratios according to the dynamic load if supported
@@ -489,7 +489,7 @@ class LoadBalancer implements ILoadBalancer {
 
        public function getConnection( $i, $groups = [], $wiki = false ) {
                if ( $i === null || $i === false ) {
-                       throw new MWException( 'Attempt to call ' . __METHOD__ .
+                       throw new InvalidArgumentException( 'Attempt to call ' . __METHOD__ .
                                ' with invalid server index' );
                }
 
@@ -578,7 +578,7 @@ class LoadBalancer implements ILoadBalancer {
                        $wiki = $dbName;
                }
                if ( $this->mConns['foreignUsed'][$serverIndex][$wiki] !== $conn ) {
-                       throw new MWException( __METHOD__ . ": connection not found, has " .
+                       throw new InvalidArgumentException( __METHOD__ . ": connection not found, has " .
                                "the connection been freed already?" );
                }
                $conn->setLBInfo( 'foreignPoolRefCount', --$refCount );
@@ -768,7 +768,7 @@ class LoadBalancer implements ILoadBalancer {
                }
 
                if ( !is_array( $server ) ) {
-                       throw new MWException( 'You must update your load-balancing configuration. ' .
+                       throw new InvalidArgumentException( 'You must update your load-balancing configuration. ' .
                                'See DefaultSettings.php entry for $wgDBservers.' );
                }