Merge "Replace unspecific exceptions with InvalidArgumentException"
This commit is contained in:
commit
25f83a9ce6
9 changed files with 15 additions and 19 deletions
|
|
@ -684,7 +684,7 @@ class HookContainer implements SalvageableService {
|
|||
return "$on::$func";
|
||||
}
|
||||
|
||||
throw new LogicException( 'Unexpected kind of callable' );
|
||||
throw new InvalidArgumentException( 'Unexpected kind of callable' );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ namespace MediaWiki\Rest\Handler\Helper;
|
|||
use Content;
|
||||
use HttpError;
|
||||
use IBufferingStatsdDataFactory;
|
||||
use InvalidArgumentException;
|
||||
use LanguageCode;
|
||||
use Liuggio\StatsdClient\Factory\StatsdDataFactoryInterface;
|
||||
use LogicException;
|
||||
|
|
@ -203,7 +204,7 @@ class HtmlOutputRendererHelper implements HtmlOutputHelper {
|
|||
*/
|
||||
public function setFlavor( string $flavor ): void {
|
||||
if ( !in_array( $flavor, self::OUTPUT_FLAVORS ) ) {
|
||||
throw new LogicException( 'Invalid flavor supplied' );
|
||||
throw new InvalidArgumentException( 'Invalid flavor supplied' );
|
||||
}
|
||||
|
||||
if ( $this->stash ) {
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace MediaWiki\Settings\Source\Format;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use LogicException;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
|
@ -46,7 +47,7 @@ class YamlFormat implements SettingsFormat {
|
|||
case self::PARSER_SYMFONY:
|
||||
return true;
|
||||
default:
|
||||
throw new LogicException( 'Unknown parser: ' . $parser );
|
||||
throw new InvalidArgumentException( 'Unknown parser: ' . $parser );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +63,7 @@ class YamlFormat implements SettingsFormat {
|
|||
case self::PARSER_SYMFONY:
|
||||
return $this->parseWithSymfony( $data );
|
||||
default:
|
||||
throw new LogicException( 'Unknown parser: ' . $parser );
|
||||
throw new InvalidArgumentException( 'Unknown parser: ' . $parser );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1583,7 +1583,7 @@ abstract class ApiBase extends ContextSource {
|
|||
*/
|
||||
public function dieStatus( StatusValue $status ) {
|
||||
if ( $status->isGood() ) {
|
||||
throw new LogicException( 'Successful status passed to ApiBase::dieStatus' );
|
||||
throw new InvalidArgumentException( 'Successful status passed to ApiBase::dieStatus' );
|
||||
}
|
||||
|
||||
foreach ( self::MESSAGE_CODE_MAP as $msg => [ $apiMsg, $code ] ) {
|
||||
|
|
|
|||
|
|
@ -21,7 +21,6 @@
|
|||
|
||||
namespace MediaWiki\ChangeTags;
|
||||
|
||||
use BadMethodCallException;
|
||||
use InvalidArgumentException;
|
||||
use ManualLogEntry;
|
||||
use MediaWiki\Config\ServiceOptions;
|
||||
|
|
@ -155,7 +154,7 @@ class ChangeTagsStore {
|
|||
IReadableDatabase $db, $rc_id = null, $rev_id = null, $log_id = null
|
||||
): array {
|
||||
if ( !$rc_id && !$rev_id && !$log_id ) {
|
||||
throw new BadMethodCallException(
|
||||
throw new InvalidArgumentException(
|
||||
'At least one of: RCID, revision ID, and log ID MUST be ' .
|
||||
'specified when loading tags from a change!' );
|
||||
}
|
||||
|
|
@ -545,7 +544,7 @@ class ChangeTagsStore {
|
|||
);
|
||||
|
||||
if ( !$rc_id && !$rev_id && !$log_id ) {
|
||||
throw new BadMethodCallException( 'At least one of: RCID, revision ID, and log ID MUST be ' .
|
||||
throw new InvalidArgumentException( 'At least one of: RCID, revision ID, and log ID MUST be ' .
|
||||
'specified when adding or removing a tag from a change!' );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -157,17 +157,13 @@ abstract class ContentHandler {
|
|||
*/
|
||||
public static function makeContent( $text, Title $title = null,
|
||||
$modelId = null, $format = null ) {
|
||||
if ( $modelId === null ) {
|
||||
if ( $title === null ) {
|
||||
throw new BadMethodCallException( "Must provide a Title object or a content model ID." );
|
||||
}
|
||||
|
||||
$modelId = $title->getContentModel();
|
||||
if ( !$title && !$modelId ) {
|
||||
throw new InvalidArgumentException( "Must provide a Title object or a content model ID." );
|
||||
}
|
||||
|
||||
return MediaWikiServices::getInstance()
|
||||
->getContentHandlerFactory()
|
||||
->getContentHandler( $modelId )
|
||||
->getContentHandler( $modelId ?? $title->getContentModel() )
|
||||
->unserializeContent( $text, $format );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1224,7 +1224,7 @@ class FormatMetadata extends ContextSource {
|
|||
*/
|
||||
private function langItem( $value, $lang, $default = false, $noHtml = false ) {
|
||||
if ( $lang === false && $default === false ) {
|
||||
throw new BadMethodCallException( '$lang and $default cannot both be false.' );
|
||||
throw new InvalidArgumentException( '$lang and $default cannot both be false.' );
|
||||
}
|
||||
|
||||
if ( $noHtml ) {
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ class ThumbnailImage extends MediaTransformOutput {
|
|||
$enableLegacyMediaDOM = $mainConfig->get( MainConfigNames::ParserEnableLegacyMediaDOM );
|
||||
|
||||
if ( func_num_args() === 2 ) {
|
||||
throw new BadMethodCallException( __METHOD__ . ' called in the old style' );
|
||||
throw new InvalidArgumentException( __METHOD__ . ' called in the old style' );
|
||||
}
|
||||
|
||||
$query = $options['desc-query'] ?? '';
|
||||
|
|
|
|||
|
|
@ -796,7 +796,6 @@ abstract class AuthManagerSpecialPage extends SpecialPage {
|
|||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
* @throws LogicException
|
||||
*/
|
||||
protected static function mapFieldInfoTypeToFormDescriptorType( $type ) {
|
||||
$map = [
|
||||
|
|
@ -810,7 +809,7 @@ abstract class AuthManagerSpecialPage extends SpecialPage {
|
|||
'null' => 'info',
|
||||
];
|
||||
if ( !array_key_exists( $type, $map ) ) {
|
||||
throw new LogicException( 'invalid field type: ' . $type );
|
||||
throw new InvalidArgumentException( 'invalid field type: ' . $type );
|
||||
}
|
||||
return $map[$type];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue