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 877d6975255..0561d86f867 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 InterpreterResult interpret(String cmd, InterpreterContext contextInterpr * @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 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 8866e6ce1c1..1228ec46a60 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 @@ private String answerFromPythonMock(InvocationOnMock invocationOnMock) { } } + @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); + } + }