Manybubbles has uploaded a new change for review.

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

Change subject: Better handling for regex and partial errors
......................................................................

Better handling for regex and partial errors

Sometimes Elasticsearch throws the regex errors back with different text.
Handle that.

Elastica fails to extract useful text from PartialShardFailures.  Do it
properly on our side.

Change-Id: I7c1a8281388b1ff4b6aea4f5fb176b14317d9bce
---
M includes/ElasticsearchIntermediary.php
1 file changed, 18 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch 
refs/changes/57/172257/1

diff --git a/includes/ElasticsearchIntermediary.php 
b/includes/ElasticsearchIntermediary.php
index a6a9a91..639fb02 100644
--- a/includes/ElasticsearchIntermediary.php
+++ b/includes/ElasticsearchIntermediary.php
@@ -1,6 +1,7 @@
 <?php
 
 namespace CirrusSearch;
+use Elastica\Exception\PartialShardFailureException;
 use Elastica\Exception\ResponseException;
 use \ElasticaConnection;
 use \Status;
@@ -112,9 +113,18 @@
         * @return message from the exception
         */
        public static function extractMessage( $exception ) {
-               return $exception instanceof ResponseException ?
-                       $exception->getElasticsearchException()->getMessage() :
-                       $exception->getMessage();
+               if ( !( $exception instanceof ResponseException ) ) {
+                       return $exception->getMessage();
+               }
+               if ( $exception instanceof PartialShardFailureException ) {
+                       $shardStats = 
$exception->getResponse()->getShardsStatistics();
+                       $message = array();
+                       foreach ( $shardStats[ 'failures' ] as $failure ) {
+                               $message[] = $failure[ 'reason' ];
+                       }
+                       return 'Partial failure:  ' . implode( ',', $message );
+               }
+               return $exception->getElasticsearchException()->getMessage();
        }
 
        /**
@@ -192,11 +202,14 @@
                        return array( Status::newFatal( 
'cirrussearch-parse-error' ), 'Parse error on ' . $parseError );
                }
 
-               $marker = 'TooComplexToDeterminizeException';
+               $marker = 'Determinizing';
                $markerLocation = strpos( $message, $marker );
                if ( $markerLocation !== false ) {
-                       $startOfMessage = $markerLocation + strlen( $marker ) + 
1;
+                       $startOfMessage = $markerLocation;
                        $endOfMessage = strpos( $message, ']; nested', 
$startOfMessage );
+                       if ( $endOfMessage === false ) {
+                               $endOfMessage = strpos( $message, '; 
Determinizing', $startOfMessage );
+                       }
                        $extracted = substr( $message, $startOfMessage, 
$endOfMessage - $startOfMessage );
                        return array( Status::newFatal( 
'cirrussearch-regex-too-complex-error' ), $extracted );
                }

-- 
To view, visit https://gerrit.wikimedia.org/r/172257
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7c1a8281388b1ff4b6aea4f5fb176b14317d9bce
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CirrusSearch
Gerrit-Branch: master
Gerrit-Owner: Manybubbles <never...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to