summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/search/searchers
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2020-08-18 11:15:50 +0200
committerJon Bratseth <bratseth@gmail.com>2020-08-18 11:15:50 +0200
commitc30bbdb0fa50cedc56eec71feeadc969ba5a3edf (patch)
tree6935b4d042618900ee0f7fd291c14ed55ae06cf8 /container-search/src/main/java/com/yahoo/search/searchers
parent529694a88d48270298171fdcb87d1439f183202b (diff)
Skip logging only for IllegalInputException
- Add IllegalInputException to signal cases where we know the exception is caused by illegal input received from the requestor. - Only skip logging for IllegalInputException instead of the superclass IllegalArgumentException as that is also used to signal illegal arguments to methods due to bugs which are otherwise hard to debug. - Throw IllegalInputException rather than IllegalArgumentException where appropriate. - Deprecated QueryException as it was only used to be able to separate between query string and query parameter exceptions, and not doing that consistently, and is in a package we don't want more use of. - Clean up some cases where the wrong exception was thrown.
Diffstat (limited to 'container-search/src/main/java/com/yahoo/search/searchers')
-rw-r--r--container-search/src/main/java/com/yahoo/search/searchers/InputCheckingSearcher.java21
1 files changed, 11 insertions, 10 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/searchers/InputCheckingSearcher.java b/container-search/src/main/java/com/yahoo/search/searchers/InputCheckingSearcher.java
index 3c0453f8900..5e15a8ba14b 100644
--- a/container-search/src/main/java/com/yahoo/search/searchers/InputCheckingSearcher.java
+++ b/container-search/src/main/java/com/yahoo/search/searchers/InputCheckingSearcher.java
@@ -19,11 +19,13 @@ import com.yahoo.prelude.query.Item;
import com.yahoo.prelude.query.PhraseItem;
import com.yahoo.prelude.query.TermItem;
import com.yahoo.prelude.query.WordItem;
+import com.yahoo.processing.IllegalInputException;
import com.yahoo.search.Query;
import com.yahoo.search.Result;
import com.yahoo.search.Searcher;
import com.yahoo.search.result.ErrorMessage;
import com.yahoo.search.searchchain.Execution;
+import com.yahoo.yolean.Exceptions;
/**
* Check whether the query tree seems to be "well formed". In other words, run heurestics against
@@ -50,10 +52,8 @@ public class InputCheckingSearcher extends Searcher {
public Result search(Query query, Execution execution) {
try {
checkQuery(query);
- } catch (IllegalArgumentException e) {
- if (log.isLoggable(Level.FINE)) {
- log.log(Level.FINE, "Rejected query \"" + query.toString() + "\" on cause of: " + e.getMessage());
- }
+ } catch (IllegalInputException e) {
+ log.log(Level.FINE, () -> "Rejected query '" + query.toString() + "' on cause of: " + Exceptions.toMessageString(e));
return new Result(query, ErrorMessage.createIllegalQuery(e.getMessage()));
}
return execution.search(query);
@@ -92,8 +92,9 @@ public class InputCheckingSearcher extends Searcher {
repeatedCount++;
if (repeatedCount >= MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE) {
repeatedConsecutiveTermsInPhraseRejections.add();
- throw new IllegalArgumentException("More than " + MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE +
- " ocurrences of term '" + current + "' in a row detected in phrase : " + phrase.toString());
+ throw new IllegalInputException("More than " + MAX_REPEATED_CONSECUTIVE_TERMS_IN_PHRASE +
+ " occurrences of term '" + current +
+ "' in a row detected in phrase : " + phrase.toString());
}
} else {
repeatedCount = 0;
@@ -125,8 +126,8 @@ public class InputCheckingSearcher extends Searcher {
if (count != null) {
if (count.get() >= MAX_REPEATED_TERMS_IN_PHRASE) {
repeatedTermsInPhraseRejections.add();
- throw new IllegalArgumentException("Phrase contains more than " + MAX_REPEATED_TERMS_IN_PHRASE +
- " occurrences of term '" + current + "' in phrase : " + phrase.toString());
+ throw new IllegalInputException("Phrase contains more than " + MAX_REPEATED_TERMS_IN_PHRASE +
+ " occurrences of term '" + current + "' in phrase : " + phrase.toString());
}
count.inc();
} else {
@@ -169,8 +170,8 @@ public class InputCheckingSearcher extends Searcher {
return;
}
utfRejections.add();
- throw new IllegalArgumentException("The user input has been determined to be double encoded UTF-8."
- + " Please investigate whether this is a false positive.");
+ throw new IllegalInputException("The user input has been determined to be double encoded UTF-8."
+ + " Please investigate whether this is a false positive.");
}
private int countSingleCharacterUserTerms(Item queryItem) {