This is an automated email from the ASF dual-hosted git repository.
mboehm7 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/master by this push:
new 8a602ca [SYSTEMDS-615] Improved error handling parser syntax errors
8a602ca is described below
commit 8a602caa135e7720024d95b7192cb7008678fd57
Author: Matthias Boehm <[email protected]>
AuthorDate: Fri Jul 24 22:04:55 2020 +0200
[SYSTEMDS-615] Improved error handling parser syntax errors
---
.../apache/sysds/parser/dml/CustomErrorListener.java | 18 ++++++++----------
.../test/functions/mlcontext/MLContextTest.java | 20 ++++++++++++++++++++
2 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/src/main/java/org/apache/sysds/parser/dml/CustomErrorListener.java
b/src/main/java/org/apache/sysds/parser/dml/CustomErrorListener.java
index 13e5f77..619a2ac 100644
--- a/src/main/java/org/apache/sysds/parser/dml/CustomErrorListener.java
+++ b/src/main/java/org/apache/sysds/parser/dml/CustomErrorListener.java
@@ -136,19 +136,17 @@ public class CustomErrorListener extends
BaseErrorListener {
* Syntax error occurred. Add the error to the list of parse issues.
*/
@Override
- public void syntaxError(Recognizer<?, ?> recognizer, Object
offendingSymbol, int line, int charPositionInLine,
- String msg, RecognitionException e) {
+ public void syntaxError(Recognizer<?, ?> recognizer, Object
offendingSymbol,
+ int line, int charPositionInLine, String msg,
RecognitionException e)
+ {
+ msg = msg + " ("+offendingSymbol.toString()+")";
parseIssues.add(new ParseIssue(line, charPositionInLine, msg,
currentFileName, ParseIssueType.SYNTAX_ERROR));
try {
setAtLeastOneError(true);
- // Print error messages with file name
- if (currentFileName == null)
- log.error("line " + line + ":" +
charPositionInLine + " " + msg);
- else {
- String fileName = currentFileName;
- log.error(fileName + " line " + line + ":" +
charPositionInLine + " " + msg);
- }
- } catch (Exception e1) {
+ String out = (currentFileName != null) ?
(currentFileName + ", ") : "";
+ log.error(out + "line " + line + ":" +
charPositionInLine + " " + msg);
+ }
+ catch (Exception e1) {
log.error("ERROR: while customizing error message:" +
e1);
}
}
diff --git
a/src/test/java/org/apache/sysds/test/functions/mlcontext/MLContextTest.java
b/src/test/java/org/apache/sysds/test/functions/mlcontext/MLContextTest.java
index ac7b3e7..3e07b15 100644
--- a/src/test/java/org/apache/sysds/test/functions/mlcontext/MLContextTest.java
+++ b/src/test/java/org/apache/sysds/test/functions/mlcontext/MLContextTest.java
@@ -1494,6 +1494,26 @@ public class MLContextTest extends MLContextTestBase {
setExpectedStdOut("3 15.000000");
ml.execute(script);
}
+
+ @Test
+ public void testErrorHandlingTwoIdentifiers() {
+ try {
+ System.out.println("MLContextTest - error handling two
identifiers");
+ Script script = dml("foo bar");
+ ml.execute(script);
+ }
+ catch(Exception ex) {
+ Throwable t = ex;
+ while( t.getCause() != null )
+ t = t.getCause();
+ System.out.println(t.getMessage());
+ Assert.assertTrue(t.getMessage().contains("foo bar"));
+ //unfortunately, the generated antlr parser creates the
concatenated msg
+ //we do a best effort error reporting here, by adding
the offending symbol
+ //Assert.assertFalse(t.getMessage().contains("foobar"));
+ Assert.assertTrue(t.getMessage().contains("'bar'"));
+ }
+ }
@Test
public void testInputVariablesAddLongsDML() {