r113026 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113025‎ | r113026 | r113027 >
Date:12:35, 5 March 2012
Author:nikerabbit
Status:ok
Tags:i18nreview 
Comment:
Replace some return nulls with exceptions to give more information when debugging
Modified paths:
  • /trunk/extensions/Translate/utils/TranslationHelpers.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/utils/TranslationHelpers.php
@@ -297,7 +297,7 @@
298298 self::reportTranslationServiceFailure( $serviceName );
299299 } elseif ( !is_array( $response ) ) {
300300 error_log( __METHOD__ . ': Unable to parse reply: ' . strval( $json ) );
301 - return null;
 301+ throw new TranslationHelperExpection( 'Malformed reply from remote server' );
302302 }
303303
304304 $suggestions = $response['ttmserver'];
@@ -369,7 +369,7 @@
370370
371371 /**
372372 * @param $async bool
373 - * @return null|string
 373+ * @return string
374374 * @throws MWException
375375 */
376376 public function getSuggestionBox( $async = false ) {
@@ -448,7 +448,7 @@
449449 $unsupported = wfGetCache( CACHE_ANYTHING )->get( $memckey );
450450
451451 if ( isset( $unsupported[$code] ) ) {
452 - return null;
 452+ throw new TranslationHelperExpection( 'Unsupported language' );
453453 }
454454
455455 $options = array();
@@ -462,7 +462,7 @@
463463 if ( isset( $config['key'] ) ) {
464464 $params['appId'] = $config['key'];
465465 } else {
466 - return null;
 466+ throw new TranslationHelperExpection( 'API key is not set' );
467467 }
468468
469469 $url = $config['url'] . '?' . wfArrayToCgi( $params );
@@ -483,7 +483,7 @@
484484 if ( strpos( $error, 'must be a valid language' ) !== false ) {
485485 $unsupported[$code] = true;
486486 wfGetCache( CACHE_ANYTHING )->set( $memckey, $unsupported, 60 * 60 * 8 );
487 - return null;
 487+ throw new TranslationHelperExpection( 'Unsupported language code' );
488488 }
489489
490490 if ( $error ) {
@@ -536,7 +536,7 @@
537537 self::reportTranslationServiceFailure( $serviceName );
538538 } elseif ( !is_object( $response ) ) {
539539 error_log( __METHOD__ . ': Unable to parse reply: ' . strval( $json ) );
540 - return null;
 540+ throw new TranslationHelperExpection( 'Malformed reply from remote server' );
541541 }
542542
543543 foreach ( $response->responseData as $pair ) {
@@ -558,7 +558,7 @@
559559 $code = str_replace( '-', '_', wfBCP47( $code ) );
560560
561561 if ( !isset( $pairs[$code] ) ) {
562 - return null;
 562+ throw new TranslationHelperExpection( 'Unsupported language' );
563563 }
564564
565565 $suggestions = array();
@@ -601,7 +601,7 @@
602602 }
603603
604604 if ( !count( $suggestions ) ) {
605 - return null;
 605+ throw new TranslationHelperExpection( 'No suggestions' );
606606 }
607607
608608 $divider = Html::element( 'div', array( 'style' => 'margin-bottom: 0.5ex' ) );
@@ -771,7 +771,7 @@
772772 global $wgTranslateDocumentationLanguageCode, $wgOut;
773773
774774 if ( !$wgTranslateDocumentationLanguageCode ) {
775 - return null;
 775+ throw new TranslationHelperExpection( 'Message documentation language code is not defined' );
776776 }
777777
778778 $page = $this->handle->getKey();

Status & tagging log