Improved error handling.
Change-Id: I02bc23bd62e0e58991f804c98a01325de07fcbc0
diff --git a/Changes b/Changes
index f74c7a7..3a859d4 100644
--- a/Changes
+++ b/Changes
@@ -1,7 +1,8 @@
-0.26 2017-06-28
+0.26 2017-06-29
- Updated collection query grammar (margaretha)
- Updated maven dependency phase (margaretha)
- - Fixed handling of non-necessary brackets in tokens (diewald)
+ - Fixed handling of non-necessary brackets in tokens (diewald)
+ - Improved error handling (margaretha)
0.25 2017-05-10
- Altered dominance and relation serialization (margaretha)
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
index d6f024a..53fa5bd 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
@@ -180,6 +180,13 @@
List<Object> error = Arrays.asList(new Object[] { code, msg });
errors.add(error);
}
+
+ public void addError (int code, String[] details) {
+ List<Object> error = new ArrayList<Object>();
+ error.add(code);
+ error.add(details);
+ errors.add(error);
+ }
/**
@@ -192,10 +199,19 @@
public void addError (List<Object> fullErrorMsg) {
errors.add(fullErrorMsg);
}
+
+
+ /** Retrieves a list of errors occurring in the serialization process.
+ *
+ * @return a list of errors
+ */
+ public List<List<Object>> getErrors () {
+ return errors;
+ }
/**
- * Add a class to the list of classes highlighted in KWIC view.
+ * Adds a class to the list of classes highlighted in KWIC view.
*
* @param classId
* The class ID.
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
index ba9ab97..1930a9a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
@@ -66,15 +66,13 @@
throw new NullPointerException("Parser has not been instantiated!");
}
log.info("Processing virtual collection query: " + query);
- if (verbose)
- System.out.println(tree.toStringTree(parser));
+ log.debug("ANTLR parse tree: " + tree.toStringTree(parser));
if (tree != null) {
- log.debug("ANTLR parse tree: " + tree.toStringTree(parser));
processNode(tree);
}
else {
- addError(StatusCodes.MALFORMED_QUERY, "Could not parse query >>> "
- + query + " <<<.");
+ addError(StatusCodes.MALFORMED_QUERY, new String[]{"Could not parse query >>> "
+ + query + " <<<.", query});
}
}
@@ -120,6 +118,8 @@
term.put("match", "match:" + interpretMatchOperator(match));
if (!checkOperatorValueConformance(term)) {
+ addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
+ "Operator "+match+" is not valid.");
requestMap = new HashMap<String, Object>();
return;
}
@@ -254,8 +254,6 @@
if (!(match.equals("match:eq") || match.equals("match:ne")
|| match.equals("match:contains") || match
.equals("match:containsnot"))) {
- addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
- "You used an inequation operator with a string value.");
return false;
}
}