Jeroen De Dauw has submitted this change and it was merged. 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(-) Approvals: WikidataJenkins: Verified Jeroen De Dauw: Looks good to me, approved 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/154277 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I010fc0902372e6677319dbbbcfd649d9d01d1b9d Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: master Gerrit-Owner: Aude <aude.w...@gmail.com> Gerrit-Reviewer: Jeroen De Dauw <jeroended...@gmail.com> Gerrit-Reviewer: WikidataJenkins <wikidata-servi...@wikimedia.de> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits