Replace some usages of MWException
These exceptions are not documented with @throws and they're really not meant to be caught. Bug: T86704 Change-Id: I07f32e42c6fd4bc8785bac91547858f15a9fc2a8
This commit is contained in:
parent
549cb9583f
commit
c5a01d4b2e
15 changed files with 34 additions and 60 deletions
|
|
@ -422,7 +422,7 @@ class GitInfo {
|
|||
if ( !file_exists( $cacheDir ) &&
|
||||
!wfMkdirParents( $cacheDir, null, __METHOD__ )
|
||||
) {
|
||||
throw new MWException( "Unable to create GitInfo cache \"{$cacheDir}\"" );
|
||||
throw new RuntimeException( "Unable to create GitInfo cache \"{$cacheDir}\"" );
|
||||
}
|
||||
|
||||
file_put_contents( $this->cacheFile, FormatJson::encode( $this->cache ) );
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@
|
|||
namespace MediaWiki\Maintenance;
|
||||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MWException;
|
||||
use ObjectCache;
|
||||
use RedisConnectionPool;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
* Manage forking inside CLI maintenance scripts.
|
||||
|
|
@ -65,11 +65,15 @@ class ForkController {
|
|||
*/
|
||||
public function __construct( $numProcs, $flags = 0 ) {
|
||||
if ( !wfIsCLI() ) {
|
||||
throw new MWException( "MediaWiki\Maintenance\ForkController cannot be used from the web." );
|
||||
throw new RuntimeException( "MediaWiki\Maintenance\ForkController cannot be used from the web." );
|
||||
} elseif ( !extension_loaded( 'pcntl' ) ) {
|
||||
throw new MWException( 'MediaWiki\Maintenance\ForkController requires pcntl extension to be installed.' );
|
||||
throw new RuntimeException(
|
||||
'MediaWiki\Maintenance\ForkController requires pcntl extension to be installed.'
|
||||
);
|
||||
} elseif ( !extension_loaded( 'posix' ) ) {
|
||||
throw new MWException( 'MediaWiki\Maintenance\ForkController requires posix extension to be installed.' );
|
||||
throw new RuntimeException(
|
||||
'MediaWiki\Maintenance\ForkController requires posix extension to be installed.'
|
||||
);
|
||||
}
|
||||
$this->procsToStart = $numProcs;
|
||||
$this->flags = $flags;
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ trait SearchApi {
|
|||
// are responsible for setting them (since api modules *can* have services
|
||||
// injected). Double check that the api module did indeed set them
|
||||
if ( !$this->searchEngineConfig || !$this->searchEngineFactory ) {
|
||||
throw new MWException(
|
||||
throw new LogicException(
|
||||
'SearchApi requires both a SearchEngineConfig and SearchEngineFactory to be set'
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace MediaWiki\Block;
|
|||
|
||||
use MediaWiki\HookContainer\HookContainer;
|
||||
use MediaWiki\HookContainer\HookRunner;
|
||||
use MWException;
|
||||
use UnexpectedValueException;
|
||||
|
||||
/**
|
||||
* Defines the actions that can be blocked by a partial block. They are
|
||||
|
|
@ -94,7 +94,7 @@ class BlockActionInfo {
|
|||
$this->hookRunner->onGetAllBlockActions( $this->allBlockActions );
|
||||
}
|
||||
if ( count( $this->allBlockActions ) !== count( array_unique( $this->allBlockActions ) ) ) {
|
||||
throw new MWException( 'Blockable action IDs not unique' );
|
||||
throw new UnexpectedValueException( 'Blockable action IDs not unique' );
|
||||
}
|
||||
return $this->allBlockActions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class ConcatenatedGzipHistoryBlob implements HistoryBlob {
|
|||
|
||||
public function __construct() {
|
||||
if ( !function_exists( 'gzdeflate' ) ) {
|
||||
throw new MWException( "Need zlib support to read or write this "
|
||||
throw new RuntimeException( "Need zlib support to read or write this "
|
||||
. "kind of history object (ConcatenatedGzipHistoryBlob)\n" );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -141,7 +141,7 @@ class BitmapHandler extends TransformationalImageHandler {
|
|||
case 'yuv420':
|
||||
return [ '2x2', '1x1', '1x1' ];
|
||||
default:
|
||||
throw new MWException( 'Invalid pixel format for JPEG output' );
|
||||
throw new UnexpectedValueException( 'Invalid pixel format for JPEG output' );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ class TiffHandler extends ExifBitmapHandler {
|
|||
$meta = BitmapMetadataHandler::Tiff( $filename );
|
||||
if ( !is_array( $meta ) ) {
|
||||
// This should never happen, but doesn't hurt to be paranoid.
|
||||
throw new MWException( 'Metadata array is not an array' );
|
||||
throw new UnexpectedValueException( 'Metadata array is not an array' );
|
||||
}
|
||||
$info = [
|
||||
'width' => $meta['ImageWidth'] ?? 0,
|
||||
|
|
|
|||
|
|
@ -54,13 +54,13 @@ class PoolCounterWorkViaCallback extends PoolCounterWork {
|
|||
foreach ( [ 'doWork', 'doCachedWork', 'fallback', 'error' ] as $name ) {
|
||||
if ( isset( $callbacks[$name] ) ) {
|
||||
if ( !is_callable( $callbacks[$name] ) ) {
|
||||
throw new MWException( "Invalid callback provided for '$name' function." );
|
||||
throw new InvalidArgumentException( "Invalid callback provided for '$name' function." );
|
||||
}
|
||||
$this->$name = $callbacks[$name];
|
||||
}
|
||||
}
|
||||
if ( !isset( $this->doWork ) ) {
|
||||
throw new MWException( "No callback provided for 'doWork' function." );
|
||||
throw new InvalidArgumentException( "No callback provided for 'doWork' function." );
|
||||
}
|
||||
$this->cacheable = isset( $this->doCachedWork );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ class RevDelRevisionList extends RevDelList {
|
|||
return new RevDelArchivedRevisionItem( $this, $row );
|
||||
} else {
|
||||
// This shouldn't happen. :)
|
||||
throw new MWException( 'Invalid row type in RevDelRevisionList' );
|
||||
throw new InvalidArgumentException( 'Invalid row type in RevDelRevisionList' );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
namespace MediaWiki\Session;
|
||||
|
||||
use BadMethodCallException;
|
||||
use BagOStuff;
|
||||
use CachedBagOStuff;
|
||||
use Config;
|
||||
|
|
@ -1009,7 +1010,7 @@ class SessionManager implements SessionManagerInterface {
|
|||
public static function resetCache() {
|
||||
if ( !defined( 'MW_PHPUNIT_TEST' ) && !defined( 'MW_PARSER_TEST' ) ) {
|
||||
// @codeCoverageIgnoreStart
|
||||
throw new MWException( __METHOD__ . ' may only be called from unit tests!' );
|
||||
throw new BadMethodCallException( __METHOD__ . ' may only be called from unit tests!' );
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
|
|
@ -1059,7 +1060,7 @@ class SessionManager implements SessionManagerInterface {
|
|||
}
|
||||
try {
|
||||
$ip = $session->getRequest()->getIP();
|
||||
} catch ( \MWException $e ) {
|
||||
} catch ( MWException $e ) {
|
||||
return;
|
||||
}
|
||||
if ( $ip === '127.0.0.1' || $proxyLookup->isConfiguredProxy( $ip ) ) {
|
||||
|
|
|
|||
|
|
@ -150,11 +150,7 @@ class Site {
|
|||
* @since 1.21
|
||||
* @param string|null $globalId
|
||||
*/
|
||||
public function setGlobalId( $globalId ) {
|
||||
if ( $globalId !== null && !is_string( $globalId ) ) {
|
||||
throw new MWException( '$globalId needs to be string or null' );
|
||||
}
|
||||
|
||||
public function setGlobalId( ?string $globalId ) {
|
||||
$this->globalId = $globalId;
|
||||
}
|
||||
|
||||
|
|
@ -186,11 +182,7 @@ class Site {
|
|||
* @since 1.21
|
||||
* @param string $group
|
||||
*/
|
||||
public function setGroup( $group ) {
|
||||
if ( !is_string( $group ) ) {
|
||||
throw new MWException( '$group needs to be a string' );
|
||||
}
|
||||
|
||||
public function setGroup( string $group ) {
|
||||
$this->group = $group;
|
||||
}
|
||||
|
||||
|
|
@ -211,11 +203,7 @@ class Site {
|
|||
* @since 1.21
|
||||
* @param string $source
|
||||
*/
|
||||
public function setSource( $source ) {
|
||||
if ( !is_string( $source ) ) {
|
||||
throw new MWException( '$source needs to be a string' );
|
||||
}
|
||||
|
||||
public function setSource( string $source ) {
|
||||
$this->source = $source;
|
||||
}
|
||||
|
||||
|
|
@ -238,11 +226,7 @@ class Site {
|
|||
* @since 1.21
|
||||
* @param bool $shouldForward
|
||||
*/
|
||||
public function setForward( $shouldForward ) {
|
||||
if ( !is_bool( $shouldForward ) ) {
|
||||
throw new MWException( '$shouldForward needs to be a boolean' );
|
||||
}
|
||||
|
||||
public function setForward( bool $shouldForward ) {
|
||||
$this->forward = $shouldForward;
|
||||
}
|
||||
|
||||
|
|
@ -287,7 +271,7 @@ class Site {
|
|||
|
||||
// Malformed URL
|
||||
if ( $protocol === false ) {
|
||||
throw new MWException( "failed to parse URL '$path'" );
|
||||
throw new UnexpectedValueException( "failed to parse URL '$path'" );
|
||||
}
|
||||
|
||||
// No schema
|
||||
|
|
@ -311,7 +295,7 @@ class Site {
|
|||
$type = $this->getLinkPathType();
|
||||
|
||||
if ( $type === null ) {
|
||||
throw new MWException( "This Site does not support link paths." );
|
||||
throw new RuntimeException( "This Site does not support link paths." );
|
||||
}
|
||||
|
||||
$this->setPath( $type, $fullUrl );
|
||||
|
|
@ -582,11 +566,7 @@ class Site {
|
|||
* @param string $pathType
|
||||
* @param string $fullUrl
|
||||
*/
|
||||
public function setPath( $pathType, $fullUrl ) {
|
||||
if ( !is_string( $fullUrl ) ) {
|
||||
throw new MWException( '$fullUrl needs to be a string' );
|
||||
}
|
||||
|
||||
public function setPath( $pathType, string $fullUrl ) {
|
||||
if ( !array_key_exists( 'paths', $this->extraData ) ) {
|
||||
$this->extraData['paths'] = [];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,6 +114,6 @@ abstract class RedirectSpecialPage extends UnlistedSpecialPage {
|
|||
*/
|
||||
protected function showNoRedirectPage() {
|
||||
$class = static::class;
|
||||
throw new MWException( "RedirectSpecialPage $class doesn't redirect!" );
|
||||
throw new LogicException( "RedirectSpecialPage $class doesn't redirect!" );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class NamespaceImportTitleFactory implements ImportTitleFactory {
|
|||
int $ns
|
||||
) {
|
||||
if ( !$namespaceInfo->exists( $ns ) ) {
|
||||
throw new MWException( "Namespace $ns doesn't exist on this wiki" );
|
||||
throw new InvalidArgumentException( "Namespace $ns doesn't exist on this wiki" );
|
||||
}
|
||||
$this->titleFactory = $titleFactory;
|
||||
$this->ns = $ns;
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class SubpageImportTitleFactory implements ImportTitleFactory {
|
|||
Title $rootPage
|
||||
) {
|
||||
if ( !$namespaceInfo->hasSubpages( $rootPage->getNamespace() ) ) {
|
||||
throw new MWException( "The root page you specified, $rootPage, is in a " .
|
||||
throw new InvalidArgumentException( "The root page you specified, $rootPage, is in a " .
|
||||
"namespace where subpages are not allowed" );
|
||||
}
|
||||
$this->titleFactory = $titleFactory;
|
||||
|
|
|
|||
|
|
@ -79,19 +79,8 @@ class SubpageImportTitleFactoryTest extends MediaWikiIntegrationTestCase {
|
|||
$this->assertTrue( $testTitle->equals( $title ) );
|
||||
}
|
||||
|
||||
public function failureProvider() {
|
||||
return [
|
||||
[
|
||||
Title::newFromText( 'Graham' ),
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider failureProvider
|
||||
*/
|
||||
public function testFailures( Title $rootPage ) {
|
||||
$this->expectException( MWException::class );
|
||||
$this->newSubpageImportTitleFactory( $rootPage );
|
||||
public function testInvalidNamespace() {
|
||||
$this->expectException( InvalidArgumentException::class );
|
||||
$this->newSubpageImportTitleFactory( Title::newFromText( 'Graham' ) );
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue