Discussion:
[MediaWiki-commits] [Gerrit] resourceloader: Throw InvalidArgumentException for invalid c... - change (mediawiki/core)
Bartosz Dziewoński (Code Review)
2015-03-30 16:55:39 UTC
Permalink
Bartosz Dziewoński has uploaded a new change for review.

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

Change subject: resourceloader: Throw InvalidArgumentException for invalid constructor arguments
......................................................................

resourceloader: Throw InvalidArgumentException for invalid constructor arguments

(But not for exceptions about missing files.)

Per Legoktm's comments on 8edbfb5feb708f80d63f118f9b00eb341278f68a.

Change-Id: I725f846476d2d97d3d820bc22674f7b5aab812bb
---
M includes/resourceloader/ResourceLoaderFileModule.php
M includes/resourceloader/ResourceLoaderImage.php
M includes/resourceloader/ResourceLoaderImageModule.php
3 files changed, 12 insertions(+), 12 deletions(-)


git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/07/200607/1

diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php
index a46c931..db10b2c 100644
--- a/includes/resourceloader/ResourceLoaderFileModule.php
+++ b/includes/resourceloader/ResourceLoaderFileModule.php
@@ -174,7 +174,7 @@
* to $wgResourceBasePath
*
* Below is a description for the $options array:
- * @throws MWException
+ * @throws InvalidArgumentException
* @par Construction options:
* @code
* array(
@@ -255,14 +255,14 @@
case 'skinScripts':
case 'skinStyles':
if ( !is_array( $option ) ) {
- throw new MWException(
+ throw new InvalidArgumentException(
"Invalid collated file path list error. " .
"'$option' given, array expected."
);
}
foreach ( $option as $key => $value ) {
if ( !is_string( $key ) ) {
- throw new MWException(
+ throw new InvalidArgumentException(
"Invalid collated file path list key error. " .
"'$key' given, string expected."
);
diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php
index 4b16a12..7cfe2a4 100644
--- a/includes/resourceloader/ResourceLoaderImage.php
+++ b/includes/resourceloader/ResourceLoaderImage.php
@@ -44,7 +44,7 @@
* @param string|array $descriptor Path to image file, or array structure containing paths
* @param string $basePath Directory to which paths in descriptor refer
* @param array $variants
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function __construct( $name, $module, $descriptor, $basePath, $variants ) {
$this->name = $name;
@@ -61,11 +61,11 @@
} );
$extensions = array_unique( $extensions );
if ( count( $extensions ) !== 1 ) {
- throw new MWException( "File type for different image files of '$name' not the same." );
+ throw new InvalidArgumentException( "File type for different image files of '$name' not the same" );
}
$ext = $extensions[0];
if ( !isset( self::$fileTypes[$ext] ) ) {
- throw new MWException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)." );
+ throw new InvalidArgumentException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)" );
}
$this->extension = $ext;
}
diff --git a/includes/resourceloader/ResourceLoaderImageModule.php b/includes/resourceloader/ResourceLoaderImageModule.php
index 28aebdf..88ba597 100644
--- a/includes/resourceloader/ResourceLoaderImageModule.php
+++ b/includes/resourceloader/ResourceLoaderImageModule.php
@@ -85,7 +85,7 @@
* ),
* )
* @endcode
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function __construct( $options = array(), $localBasePath = null ) {
$this->localBasePath = self::extractLocalBasePath( $options, $localBasePath );
@@ -103,16 +103,16 @@
$selectorWithVariant = isset( $options['selectorWithVariant'] ) && $options['selectorWithVariant'];

if ( $selectorWithoutVariant && !$selectorWithVariant ) {
- throw new MWException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." );
+ throw new InvalidArgumentException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." );
}
if ( $selectorWithVariant && !$selectorWithoutVariant ) {
- throw new MWException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." );
+ throw new InvalidArgumentException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." );
}
if ( $selector && $selectorWithVariant ) {
- throw new MWException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." );
+ throw new InvalidArgumentException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." );
}
if ( !$prefix && !$selector && !$selectorWithVariant ) {
- throw new MWException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." );
+ throw new InvalidArgumentException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." );
}

foreach ( $options as $member => $option ) {
@@ -120,7 +120,7 @@
case 'images':
case 'variants':
if ( !is_array( $option ) ) {
- throw new MWException(
+ throw new InvalidArgumentException(
"Invalid list error. '$option' given, array expected."
);
}
--
To view, visit https://gerrit.wikimedia.org/r/200607
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I725f846476d2d97d3d820bc22674f7b5aab812bb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <***@gmail.com>
jenkins-bot (Code Review)
2015-03-30 18:13:38 UTC
Permalink
jenkins-bot has submitted this change and it was merged.

Change subject: resourceloader: Throw InvalidArgumentException for invalid constructor arguments
......................................................................


resourceloader: Throw InvalidArgumentException for invalid constructor arguments

(But not for exceptions about missing files.)

Per Legoktm's comments on 8edbfb5feb708f80d63f118f9b00eb341278f68a.

Change-Id: I725f846476d2d97d3d820bc22674f7b5aab812bb
---
M includes/resourceloader/ResourceLoaderFileModule.php
M includes/resourceloader/ResourceLoaderImage.php
M includes/resourceloader/ResourceLoaderImageModule.php
3 files changed, 12 insertions(+), 12 deletions(-)

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



diff --git a/includes/resourceloader/ResourceLoaderFileModule.php b/includes/resourceloader/ResourceLoaderFileModule.php
index a46c931..db10b2c 100644
--- a/includes/resourceloader/ResourceLoaderFileModule.php
+++ b/includes/resourceloader/ResourceLoaderFileModule.php
@@ -174,7 +174,7 @@
* to $wgResourceBasePath
*
* Below is a description for the $options array:
- * @throws MWException
+ * @throws InvalidArgumentException
* @par Construction options:
* @code
* array(
@@ -255,14 +255,14 @@
case 'skinScripts':
case 'skinStyles':
if ( !is_array( $option ) ) {
- throw new MWException(
+ throw new InvalidArgumentException(
"Invalid collated file path list error. " .
"'$option' given, array expected."
);
}
foreach ( $option as $key => $value ) {
if ( !is_string( $key ) ) {
- throw new MWException(
+ throw new InvalidArgumentException(
"Invalid collated file path list key error. " .
"'$key' given, string expected."
);
diff --git a/includes/resourceloader/ResourceLoaderImage.php b/includes/resourceloader/ResourceLoaderImage.php
index 4b16a12..d12975a 100644
--- a/includes/resourceloader/ResourceLoaderImage.php
+++ b/includes/resourceloader/ResourceLoaderImage.php
@@ -44,7 +44,7 @@
* @param string|array $descriptor Path to image file, or array structure containing paths
* @param string $basePath Directory to which paths in descriptor refer
* @param array $variants
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function __construct( $name, $module, $descriptor, $basePath, $variants ) {
$this->name = $name;
@@ -61,11 +61,11 @@
} );
$extensions = array_unique( $extensions );
if ( count( $extensions ) !== 1 ) {
- throw new MWException( "File type for different image files of '$name' not the same." );
+ throw new InvalidArgumentException( "File type for different image files of '$name' not the same." );
}
$ext = $extensions[0];
if ( !isset( self::$fileTypes[$ext] ) ) {
- throw new MWException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)." );
+ throw new InvalidArgumentException( "Invalid file type for image files of '$name' (valid: svg, png, gif, jpg)." );
}
$this->extension = $ext;
}
diff --git a/includes/resourceloader/ResourceLoaderImageModule.php b/includes/resourceloader/ResourceLoaderImageModule.php
index 28aebdf..88ba597 100644
--- a/includes/resourceloader/ResourceLoaderImageModule.php
+++ b/includes/resourceloader/ResourceLoaderImageModule.php
@@ -85,7 +85,7 @@
* ),
* )
* @endcode
- * @throws MWException
+ * @throws InvalidArgumentException
*/
public function __construct( $options = array(), $localBasePath = null ) {
$this->localBasePath = self::extractLocalBasePath( $options, $localBasePath );
@@ -103,16 +103,16 @@
$selectorWithVariant = isset( $options['selectorWithVariant'] ) && $options['selectorWithVariant'];

if ( $selectorWithoutVariant && !$selectorWithVariant ) {
- throw new MWException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." );
+ throw new InvalidArgumentException( "Given 'selectorWithoutVariant' but no 'selectorWithVariant'." );
}
if ( $selectorWithVariant && !$selectorWithoutVariant ) {
- throw new MWException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." );
+ throw new InvalidArgumentException( "Given 'selectorWithVariant' but no 'selectorWithoutVariant'." );
}
if ( $selector && $selectorWithVariant ) {
- throw new MWException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." );
+ throw new InvalidArgumentException( "Incompatible 'selector' and 'selectorWithVariant'+'selectorWithoutVariant' given." );
}
if ( !$prefix && !$selector && !$selectorWithVariant ) {
- throw new MWException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." );
+ throw new InvalidArgumentException( "None of 'prefix', 'selector' or 'selectorWithVariant'+'selectorWithoutVariant' given." );
}

foreach ( $options as $member => $option ) {
@@ -120,7 +120,7 @@
case 'images':
case 'variants':
if ( !is_array( $option ) ) {
- throw new MWException(
+ throw new InvalidArgumentException(
"Invalid list error. '$option' given, array expected."
);
}
--
To view, visit https://gerrit.wikimedia.org/r/200607
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I725f846476d2d97d3d820bc22674f7b5aab812bb
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <***@gmail.com>
Gerrit-Reviewer: Jforrester <***@wikimedia.org>
Gerrit-Reviewer: Krinkle <***@gmail.com>
Gerrit-Reviewer: Legoktm <***@gmail.com>
Gerrit-Reviewer: jenkins-bot <>
Loading...