Use RuntimeException/LogicException instead of Exception

Change-Id: Idabce4eaa8b4f49701232916d2e95b71f4287e75
这个提交包含在:
Umherirrender 2024-02-23 22:25:41 +01:00
父节点 2d559210c5
当前提交 8383332e33
共有 11 个文件被更改,包括 37 次插入34 次删除

查看文件

@ -2,9 +2,6 @@
$cfg = require __DIR__ . '/../vendor/mediawiki/mediawiki-phan-config/src/config.php';
// To migrate later
$cfg['suppress_issue_types'][] = 'MediaWikiNoBaseException';
$cfg['directory_list'] = array_merge(
$cfg['directory_list'],
[

查看文件

@ -21,7 +21,6 @@
namespace MediaWiki\Extension\CentralAuth;
use BagOStuff;
use Exception;
use MediaWiki\Auth\AuthManager;
use MediaWiki\Config\Config;
use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
@ -36,6 +35,7 @@ use MWCryptRand;
use Profiler;
use Psr\Log\LoggerInterface;
use RequestContext;
use RuntimeException;
use StatusValue;
use Wikimedia\WaitConditionLoop;
@ -200,7 +200,7 @@ class CentralAuthUtilityService {
$title = $this->titleFactory->makeTitleSafe( NS_USER, $name );
if ( !$title ) {
throw new Exception( "Failed to create title for user page of $name" );
throw new RuntimeException( "Failed to create title for user page of $name" );
}
foreach ( $this->config->get( 'CentralAuthAutoCreateWikis' ) as $wiki ) {

查看文件

@ -22,8 +22,8 @@
namespace MediaWiki\Extension\CentralAuth\GlobalRename;
use BadMethodCallException;
use Exception;
use IDBAccessObject;
use InvalidArgumentException;
use MediaWiki\Extension\CentralAuth\CentralAuthServices;
use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
use MediaWiki\MediaWikiServices;
@ -185,13 +185,12 @@ class GlobalRenameRequest {
/**
* @param string $newName
* @throws Exception if an invalid username is provided
* @return GlobalRenameRequest self, for message chaining
*/
public function setNewName( $newName ) {
$canonicalName = $this->userNameUtils->getCanonical( $newName, UserNameUtils::RIGOR_CREATABLE );
if ( $canonicalName === false ) {
throw new Exception( "Invalid username '{$newName}'" );
throw new InvalidArgumentException( "Invalid username '{$newName}'" );
}
$this->newName = $canonicalName;
return $this;

查看文件

@ -2,7 +2,7 @@
namespace MediaWiki\Extension\CentralAuth\GlobalRename\LocalRenameJob;
use Exception;
use LogicException;
use MediaWiki\Extension\CentralAuth\User\CentralAuthUser;
use MediaWiki\MediaWikiServices;
use MediaWiki\RenameUser\RenameuserSQL;
@ -93,7 +93,7 @@ class LocalRenameUserJob extends LocalRenameJob {
// This should never happen!
// If it does happen, the user will be locked out of their account
// until a sysadmin intervenes...
throw new Exception( 'RenameuserSQL::rename returned false.' );
throw new LogicException( 'RenameuserSQL::rename returned false.' );
}
if ( $this->params['reattach'] ) {
$caUser = CentralAuthUser::getInstanceByName( $this->params['to'] );
@ -125,11 +125,11 @@ class LocalRenameUserJob extends LocalRenameJob {
if ( !$status->isOK() ) {
if ( $status->hasMessage( 'promote-not-on-wiki' ) ) {
// Eh, what?
throw new Exception( "Tried to promote '$newName' to a global account except it " .
throw new LogicException( "Tried to promote '$newName' to a global account except it " .
"doesn't exist locally" );
} elseif ( $status->hasMessage( 'promote-already-exists' ) ) {
// Even more wtf.
throw new Exception( "Tried to prommote '$newName' to a global account except it " .
throw new LogicException( "Tried to prommote '$newName' to a global account except it " .
"already exists" );
}
}

查看文件

@ -5,6 +5,7 @@ namespace MediaWiki\Extension\CentralAuth\Special;
use DerivativeContext;
use Exception;
use HTMLForm;
use InvalidArgumentException;
use LogEventsList;
use MediaWiki\Block\Restriction\ActionRestriction;
use MediaWiki\Block\Restriction\NamespaceRestriction;
@ -860,7 +861,7 @@ class SpecialCentralAuth extends SpecialPage {
private function formatEditcount( $row ) {
$wiki = WikiMap::getWiki( $row['wiki'] );
if ( !$wiki ) {
throw new Exception( "Invalid wiki: {$row['wiki']}" );
throw new InvalidArgumentException( "Invalid wiki: {$row['wiki']}" );
}
$wikiname = $wiki->getDisplayName();
$editCount = $this->getLanguage()->formatNum( intval( $row['editCount'] ) );
@ -916,7 +917,7 @@ class SpecialCentralAuth extends SpecialPage {
} else {
$wiki = WikiMap::getWiki( $wikiID );
if ( !$wiki ) {
throw new Exception( "Invalid wiki: $wikiID" );
throw new InvalidArgumentException( "Invalid wiki: $wikiID" );
}
}
@ -940,7 +941,7 @@ class SpecialCentralAuth extends SpecialPage {
private function foreignUserLink( $wikiID ) {
$wiki = WikiMap::getWiki( $wikiID );
if ( !$wiki ) {
throw new Exception( "Invalid wiki: $wikiID" );
throw new InvalidArgumentException( "Invalid wiki: $wikiID" );
}
$wikiname = $wiki->getDisplayName();

查看文件

@ -28,6 +28,7 @@ use MobileContext;
use MWCryptRand;
use Psr\Log\LoggerInterface;
use RequestContext;
use RuntimeException;
use SkinTemplate;
use Wikimedia\Rdbms\ReadOnlyMode;
use Wikimedia\ScopedCallback;
@ -118,7 +119,7 @@ class SpecialCentralAutoLogin extends UnlistedSpecialPage {
protected static function getInlineScript( $name ) {
$filePath = __DIR__ . '/../../modules/inline/' . $name;
if ( !file_exists( $filePath ) ) {
throw new Exception( __METHOD__ . ": file not found: \"$filePath\"" );
throw new RuntimeException( __METHOD__ . ": file not found: \"$filePath\"" );
}
$rawScript = file_get_contents( $filePath );

查看文件

@ -21,6 +21,7 @@ use MediaWiki\User\UserIdentity;
use MediaWiki\WikiMap\WikiMap;
use MWCryptRand;
use Psr\Log\LoggerInterface;
use RuntimeException;
use Wikimedia\ScopedCallback;
/**
@ -141,15 +142,15 @@ class SpecialCentralLogin extends UnlistedSpecialPage {
$getException = static function ( CentralAuthUser $centralUser, UserIdentity $user, array $info ) {
if ( !$centralUser->exists() ) {
return new Exception( "Global user '{$info['name']}' does not exist." );
return new RuntimeException( "Global user '{$info['name']}' does not exist." );
}
if ( $centralUser->getId() !== $info['guid'] ) {
return new Exception( "Global user does not have ID '{$info['guid']}'." );
return new RuntimeException( "Global user does not have ID '{$info['guid']}'." );
}
if ( !$centralUser->isAttached() && $user->isRegistered() ) {
return new Exception( "User '{$info['name']}' exists locally but is not attached." );
return new RuntimeException( "User '{$info['name']}' exists locally but is not attached." );
}
return null;
@ -285,13 +286,13 @@ class SpecialCentralLogin extends UnlistedSpecialPage {
$getException = static function ( CentralAuthUser $centralUser, UserIdentity $user ) {
if ( !$user->getId() ) {
return new Exception( "The user account logged into does not exist." );
return new RuntimeException( "The user account logged into does not exist." );
}
if ( !$centralUser->getId() ) {
return new Exception( "The central user account does not exist." );
return new RuntimeException( "The central user account does not exist." );
}
if ( !$centralUser->isAttached() ) {
return new Exception( "The user account is not attached." );
return new RuntimeException( "The user account is not attached." );
}
return null;
};

查看文件

@ -13,6 +13,7 @@
namespace MediaWiki\Extension\CentralAuth\Special;
use Exception;
use InvalidArgumentException;
use LogEventsList;
use LogPage;
use ManualLogEntry;
@ -251,7 +252,7 @@ class SpecialGlobalGroupPermissions extends SpecialPage {
if ( $wikiset !== 0 ) {
$wikiset = WikiSet::newFromID( $wikiset );
if ( !$wikiset ) {
throw new Exception( "__METHOD__: $group with unknown wikiset." );
throw new InvalidArgumentException( "__METHOD__: $group with unknown wikiset." );
}
$info['wikiset'] = [
'id' => $wikiset->getId(),

查看文件

@ -22,7 +22,6 @@
namespace MediaWiki\Extension\CentralAuth\Special;
use Exception;
use ExtensionRegistry;
use HTMLForm;
use LogEventsList;
@ -47,6 +46,7 @@ use MediaWiki\User\User;
use MediaWiki\User\UserNameUtils;
use MediaWiki\WikiMap\WikiMap;
use OOUI\MessageWidget;
use RuntimeException;
use UserMailer;
use Wikimedia\Rdbms\LBFactory;
use Xml;
@ -364,7 +364,7 @@ class SpecialGlobalRenameQueue extends SpecialPage {
$renamer = CentralAuthUser::newFromId( $req->getPerformer() );
if ( $renamer === false ) {
throw new Exception(
throw new RuntimeException(
"The performer's global user id ({$req->getPerformer()}) " .
"does not exist in the database"
);

查看文件

@ -13,6 +13,7 @@ use MediaWiki\Title\NamespaceInfo;
use MediaWiki\User\UserFactory;
use MediaWiki\WikiMap\WikiMap;
use MWCryptRand;
use RuntimeException;
use Wikimedia\AtEase\AtEase;
use Xml;
@ -331,7 +332,7 @@ class SpecialMergeAccount extends SpecialPage {
$passwords = $this->getWorkingPasswords();
if ( !$passwords ) {
throw new Exception( "Submission error -- invalid input" );
throw new RuntimeException( "Submission error -- invalid input" );
}
$globalUser->storeAndMigrate(
@ -349,11 +350,11 @@ class SpecialMergeAccount extends SpecialPage {
$globalUser = CentralAuthUser::getPrimaryInstance( $this->getUser() );
if ( !$globalUser->exists() ) {
throw new Exception( "User doesn't exist -- race condition?" );
throw new RuntimeException( "User doesn't exist -- race condition?" );
}
if ( !$globalUser->isAttached() ) {
throw new Exception( "Can't cleanup merge if not already attached." );
throw new RuntimeException( "Can't cleanup merge if not already attached." );
}
if ( $this->getConfig()->get( 'CentralAuthDryRun' ) ) {
@ -381,7 +382,7 @@ class SpecialMergeAccount extends SpecialPage {
$globalUser = CentralAuthUser::getPrimaryInstance( $this->getUser() );
if ( !$globalUser->exists() ) {
throw new Exception( "User doesn't exist -- race condition?" );
throw new RuntimeException( "User doesn't exist -- race condition?" );
}
if ( $globalUser->isAttached() ) {
@ -571,7 +572,7 @@ class SpecialMergeAccount extends SpecialPage {
private function foreignUserLink( $wikiID ) {
$wiki = WikiMap::getWiki( $wikiID );
if ( !$wiki ) {
throw new Exception( "Invalid wiki: $wikiID" );
throw new InvalidArgumentException( "Invalid wiki: $wikiID" );
}
$wikiname = $wiki->getDisplayName();

查看文件

@ -21,12 +21,14 @@
namespace MediaWiki\Extension\CentralAuth\User;
use AbstractPbkdf2Password;
use BadMethodCallException;
use CentralAuthSessionProvider;
use Exception;
use FormattedRCFeed;
use IContextSource;
use IDBAccessObject;
use InvalidArgumentException;
use LogicException;
use ManualLogEntry;
use MapCacheLRU;
use MediaWiki\Block\DatabaseBlock;
@ -825,7 +827,7 @@ class CentralAuthUser implements IDBAccessObject {
*/
public function getHiddenLevel(): int {
// Have it like this for one train, then rename getHiddenLevelInt to this
throw new Exception( 'Nothing should call this!' );
throw new BadMethodCallException( 'Nothing should call this!' );
}
/**
@ -1082,7 +1084,7 @@ class CentralAuthUser implements IDBAccessObject {
*/
public function chooseHomeWiki( $migrationSet ) {
if ( !$migrationSet ) {
throw new Exception( 'Logic error -- empty migration set in chooseHomeWiki' );
throw new LogicException( 'Logic error -- empty migration set in chooseHomeWiki' );
}
// Sysops get priority
@ -1541,7 +1543,7 @@ class CentralAuthUser implements IDBAccessObject {
if ( count( $valid ) != count( $list ) ) {
// fixme: handle this gracefully
throw new Exception( "Invalid input" );
throw new RuntimeException( "Invalid input" );
}
return $valid;
@ -3022,7 +3024,7 @@ class CentralAuthUser implements IDBAccessObject {
[
'globalId' => $this->mGlobalId,
'from' => $from,
'exception' => new Exception( 'CentralAuth gu_cas_token conflict' ),
'exception' => new RuntimeException,
]
);
return;