Aude has uploaded a new change for review.
https://gerrit.wikimedia.org/r/154279
Change subject: Handle MonolingualTextParser errors for values with language
not set
......................................................................
Handle MonolingualTextParser errors for values with language not set
Throw a ParseException and then the api response can handle that,
providing appropriate error response.
Bug: 69608
Change-Id: I010fc0902372e6677319dbbbcfd649d9d01d1b9d
---
M lib/includes/parsers/MonolingualTextParser.php
M lib/tests/phpunit/parsers/MonolingualTextParserTest.php
2 files changed, 10 insertions(+), 5 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase
refs/changes/79/154279/1
diff --git a/lib/includes/parsers/MonolingualTextParser.php
b/lib/includes/parsers/MonolingualTextParser.php
index 7f74188..22a1ab4 100644
--- a/lib/includes/parsers/MonolingualTextParser.php
+++ b/lib/includes/parsers/MonolingualTextParser.php
@@ -4,6 +4,7 @@
use DataValues\IllegalValueException;
use DataValues\MonolingualTextValue;
+use ValueParsers\ParseException;
use ValueParsers\StringValueParser;
/**
@@ -26,17 +27,21 @@
*
* @param string $value
*
- * @throws IllegalValueException if the "valuelang" option is missing
or empty
+ * @throws ParseException if the "valuelang" option is missing or empty
* @return MonolingualTextValue
*/
protected function stringParse( $value ) {
if ( !$this->getOptions()->hasOption( 'valuelang' ) ) {
- throw new IllegalValueException( 'Can not construct a
MonolingualTextValue without a language code.' );
+ throw new ParseException( 'Cannot construct a
MonolingualTextValue without a language code.' );
}
$lang = $this->getOptions()->getOption( 'valuelang' );
- return new MonolingualTextValue( trim( $lang ), trim( $value )
);
+ try {
+ return new MonolingualTextValue( trim( $lang ), trim(
$value ) );
+ } catch ( IllegalValueException $ex ) {
+ throw new ParseException( $ex->getMessage() );
+ }
}
}
diff --git a/lib/tests/phpunit/parsers/MonolingualTextParserTest.php
b/lib/tests/phpunit/parsers/MonolingualTextParserTest.php
index 151f65c..30d4310 100644
--- a/lib/tests/phpunit/parsers/MonolingualTextParserTest.php
+++ b/lib/tests/phpunit/parsers/MonolingualTextParserTest.php
@@ -43,7 +43,7 @@
}
/**
- * @expectedException \DataValues\IllegalValueException
+ * @expectedException \ValueParsers\ParseException
*/
public function testParse_missingLanguageOption() {
$parser = new MonolingualTextParser();
@@ -59,7 +59,7 @@
/**
* @dataProvider invalidLanguageCodeProvider
- * @expectedException \DataValues\IllegalValueException
+ * @expectedException \ValueParsers\ParseException
*/
public function testParse_invalidLanguageOption( $languageCode ) {
$options = new ParserOptions( array( 'valuelang' =>
$languageCode ) );
--
To view, visit https://gerrit.wikimedia.org/r/154279
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I010fc0902372e6677319dbbbcfd649d9d01d1b9d
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Wikibase
Gerrit-Branch: mw1.24-wmf17
Gerrit-Owner: Aude <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits