You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by bz...@apache.org on 2016/09/07 07:56:25 UTC

zeppelin git commit: [ZEPPELIN-1412] add support multiline for pythonErrorIn method on python interpreter

Repository: zeppelin
Updated Branches:
  refs/heads/master b8051970a -> 66d581136


[ZEPPELIN-1412] add support multiline for pythonErrorIn method on python interpreter

### What is this PR for?
currently, has not support multiline exception text on python interpreter.
for example:

```
Exception: blabla
```
is error.

but

```
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
Exception: test exception
```
is sucess (now)

to resolve this issue.

### What type of PR is it?
Bug Fix

### Todos
- [x] modification pythonErrorIn method
- [x] add test case

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-1412?jql=project%20%3D%20ZEPPELIN%20AND%20status%20%3D%20Open

### How should this be tested?
added test case.

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: CloverHearts <cl...@gmail.com>

Closes #1407 from cloverhearts/dev/ZEPPELIN-1412 and squashes the following commits:

e674134 [CloverHearts] add multiline support pythonErrorIn method


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/66d58113
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/66d58113
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/66d58113

Branch: refs/heads/master
Commit: 66d581136573761cc1afa94b414e65859ab3d3a3
Parents: b805197
Author: CloverHearts <cl...@gmail.com>
Authored: Tue Sep 6 15:35:45 2016 +0900
Committer: Alexander Bezzubov <bz...@apache.org>
Committed: Wed Sep 7 16:56:19 2016 +0900

----------------------------------------------------------------------
 .../zeppelin/python/PythonInterpreter.java      | 13 ++++++++++--
 .../zeppelin/python/PythonInterpreterTest.java  | 21 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/66d58113/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
----------------------------------------------------------------------
diff --git a/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java b/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
index 877d697..0561d86 100644
--- a/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
+++ b/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
@@ -150,8 +150,17 @@ public class PythonInterpreter extends Interpreter {
    * @return true if syntax error or exception has happened
    */
   private boolean pythonErrorIn(String output) {
-    Matcher errorMatcher = errorInLastLine.matcher(output);
-    return errorMatcher.find();
+    boolean isError = false;
+    String[] outputMultiline = output.split("\n");
+    Matcher errorMatcher;
+    for (String row : outputMultiline) {
+      errorMatcher = errorInLastLine.matcher(row);
+      if (errorMatcher.find() == true) {
+        isError = true;
+        break;
+      }
+    }
+    return isError;
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/66d58113/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
----------------------------------------------------------------------
diff --git a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
index 8866e6c..1228ec4 100644
--- a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
@@ -218,4 +218,25 @@ public class PythonInterpreterTest {
     }
   }
 
+  @Test
+  public void checkMultiRowErrorFails() {
+    PythonInterpreter pythonInterpreter = new PythonInterpreter(
+      PythonInterpreterTest.getPythonTestProperties()
+    );
+    pythonInterpreter.open();
+    String codeRaiseException = "raise Exception(\"test exception\")";
+    InterpreterResult ret = pythonInterpreter.interpret(codeRaiseException, null);
+
+    assertNotNull("Interpreter result for raise exception is Null", ret);
+
+    assertEquals(InterpreterResult.Code.ERROR, ret.code());
+    assertTrue(ret.message().length() > 0);
+
+    assertNotNull("Interpreter result for text is Null", ret);
+    String codePrintText = "print (\"Exception(\\\"test exception\\\")\")";
+    ret = pythonInterpreter.interpret(codePrintText, null);
+    assertEquals(InterpreterResult.Code.SUCCESS, ret.code());
+    assertTrue(ret.message().length() > 0);
+  }
+
 }