EBernhardson has uploaded a new change for review. https://gerrit.wikimedia.org/r/287271
Change subject: Throw InvalidRegexException instead of InvalidArgumentException ...................................................................... Throw InvalidRegexException instead of InvalidArgumentException Elasticsearch now reports exception messages in a much simpler form that includes the class name in snake case. Make regex exceptions use a more specific exception type so they can be recognized by the client. Bug: T133746 Change-Id: Iff63a0801064d5b45679bc9134385e6faae2a39d --- M src/main/java/org/wikimedia/search/extra/regex/ExpressionToQueryTransformer.java A src/main/java/org/wikimedia/search/extra/regex/InvalidRegexException.java M src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java 3 files changed, 11 insertions(+), 3 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/search/extra refs/changes/71/287271/1 diff --git a/src/main/java/org/wikimedia/search/extra/regex/ExpressionToQueryTransformer.java b/src/main/java/org/wikimedia/search/extra/regex/ExpressionToQueryTransformer.java index e0bc113..4b74791 100644 --- a/src/main/java/org/wikimedia/search/extra/regex/ExpressionToQueryTransformer.java +++ b/src/main/java/org/wikimedia/search/extra/regex/ExpressionToQueryTransformer.java @@ -26,12 +26,12 @@ @Override public Query alwaysTrue() { - throw new IllegalArgumentException("Can't transform always true into a query."); + throw new InvalidRegexException("Can't transform always true into a query."); } @Override public Query alwaysFalse() { - throw new IllegalArgumentException("Can't transform always false into a query."); + throw new InvalidRegexException("Can't transform always false into a query."); } @Override diff --git a/src/main/java/org/wikimedia/search/extra/regex/InvalidRegexException.java b/src/main/java/org/wikimedia/search/extra/regex/InvalidRegexException.java new file mode 100644 index 0000000..49d5334 --- /dev/null +++ b/src/main/java/org/wikimedia/search/extra/regex/InvalidRegexException.java @@ -0,0 +1,8 @@ +package org.wikimedia.search.extra.regex + +/** + * Represents a regex that was invalid + */ +public class InvalidRegexExceptions extends InvalidArgumentException { +} + diff --git a/src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java b/src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java index e4a60dd..b65518d 100644 --- a/src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java +++ b/src/main/java/org/wikimedia/search/extra/regex/SourceRegexQuery.java @@ -99,7 +99,7 @@ expression.transform(new ExpressionToQueryTransformer(ngramFieldPath))).rewrite(reader); } } catch (AutomatonTooComplexException e) { - throw new IllegalArgumentException(String.format(Locale.ROOT, + throw new InvalidRegexException(String.format(Locale.ROOT, "Regex /%s/ too complex for maxStatesTraced setting [%s]. Use a simpler regex or raise maxStatesTraced.", regex, settings.getMaxStatesTraced()), e); } -- To view, visit https://gerrit.wikimedia.org/r/287271 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Iff63a0801064d5b45679bc9134385e6faae2a39d Gerrit-PatchSet: 1 Gerrit-Project: search/extra Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits