Manybubbles has uploaded a new change for review. https://gerrit.wikimedia.org/r/161966
Change subject: Better error messaging in maintenance scripts ...................................................................... Better error messaging in maintenance scripts Hopefully no more <<the operation failed with error: "1">>. "1" isn't a useful error message. Nope. Change-Id: I3c7d0eb67e33335f08472d8d8c0518ad9b9a009a (cherry picked from commit 15b0043485d7ea217004ac0cc0d36abe30751fb4) --- M includes/ElasticsearchIntermediary.php M maintenance/updateOneSearchIndexConfig.php 2 files changed, 23 insertions(+), 8 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CirrusSearch refs/changes/66/161966/1 diff --git a/includes/ElasticsearchIntermediary.php b/includes/ElasticsearchIntermediary.php index 2d12671..c9f1b3d 100644 --- a/includes/ElasticsearchIntermediary.php +++ b/includes/ElasticsearchIntermediary.php @@ -107,6 +107,17 @@ } /** + * Extract an error message from an exception thrown by Elastica. + * @param RuntimeException $exception exception from which to extract a message + * @return message from the exception + */ + public static function extractMessage( $exception ) { + return $exception instanceof ResponseException ? + $exception->getElasticsearchException()->getMessage() : + $exception->getMessage(); + } + + /** * Does this status represent an Elasticsearch parse error? * @param $status Status to check * @return boolean is this a parse error? @@ -168,9 +179,7 @@ // Lots of times these are the same as getMessage(), but sometimes // they're not. So get the nested exception so we're sure we get // what we want. I'm looking at you PartialShardFailureException. - $message = $exception instanceof ResponseException ? - $exception->getElasticsearchException()->getMessage() : - $exception->getMessage(); + $message = self::extractMessage( $exception ); $marker = 'ParseException[Cannot parse '; $markerLocation = strpos( $message, $marker ); diff --git a/maintenance/updateOneSearchIndexConfig.php b/maintenance/updateOneSearchIndexConfig.php index b81a02e..95f4419 100644 --- a/maintenance/updateOneSearchIndexConfig.php +++ b/maintenance/updateOneSearchIndexConfig.php @@ -218,7 +218,7 @@ $this->error( "Http error communicating with Elasticsearch: $message.\n", 1 ); } catch ( \Elastica\Exception\ExceptionInterface $e ) { $type = get_class( $e ); - $message = $e->getMessage(); + $message = ElasticsearchIntermediary::extractMessage( $e ); $trace = $e->getTraceAsString(); $this->output( "\nUnexpected Elasticsearch failure.\n" ); $this->error( "Elasticsearch failed in an unexpected way. This is always a bug in CirrusSearch.\n" . @@ -397,7 +397,7 @@ $this->output( "corrected\n" ); } catch ( \Elastica\Exception\ExceptionInterface $e ) { $this->output( "failed!\n" ); - $message = $e->getMessage(); + $message = ElasticsearchIntermediary::extractMessage( $e ); $this->error( "Couldn't update mappings. Here is elasticsearch's error message: $message\n", 1 ); } } @@ -811,7 +811,9 @@ } } catch ( \Elastica\Exception\ExceptionInterface $e ) { // Note that we can't fail the master here, we have to check how many documents are in the new index in the master. - wfLogWarning( "Search backend error during reindex. Error message is: " . $e->getMessage() ); + $type = get_class( $e ); + $message = ElasticsearchIntermediary::extractMessage( $e ); + wfLogWarning( "Search backend error during reindex. Error type is '$type' and message is: $message" ); die( 1 ); } } @@ -830,8 +832,10 @@ // Random backoff with lowest possible upper bound as 16 seconds. // With the default mximum number of errors (5) this maxes out at 256 seconds. $seconds = rand( 1, pow( 2, 3 + $errors ) ); + $type = get_class( $e ); + $message = ElasticsearchIntermediary::extractMessage( $e ); $this->output( $this->indent . $messagePrefix . "Caught an error retrying as singles. " . - "Backing off for $seconds and retrying. Error:\n$e" ); + "Backing off for $seconds and retrying. Error type is '$type' and message is: $message" ); sleep( $seconds ); } } else { @@ -845,7 +849,9 @@ try { $updateResult = $this->getPageType()->addDocuments( $documents ); } catch ( \Elastica\Exception\ExceptionInterface $e ) { - $this->output( $this->indent . $messagePrefix . "Error adding documents in bulk. Retrying as singles. Error:\n$e" ); + $type = get_class( $e ); + $message = ElasticsearchIntermediary::extractMessage( $e ); + $this->output( $this->indent . $messagePrefix . "Error adding documents in bulk. Retrying as singles. Error type is '$type' and message is: $message" ); foreach ( $documents as $document ) { // Continue using the bulk api because we're used to it. $updateResult = $this->getPageType()->addDocuments( array( $document ) ); -- To view, visit https://gerrit.wikimedia.org/r/161966 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3c7d0eb67e33335f08472d8d8c0518ad9b9a009a Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/CirrusSearch Gerrit-Branch: wmf/1.24wmf21 Gerrit-Owner: Manybubbles <never...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits