You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@toree.apache.org by ch...@apache.org on 2016/09/27 14:28:10 UTC

[1/4] incubator-toree git commit: Added @transient to the _exceptionHack bind

Repository: incubator-toree
Updated Branches:
  refs/heads/master 1ea7b5671 -> 8d9e1e02f


Added @transient to the _exceptionHack bind

Project: http://git-wip-us.apache.org/repos/asf/incubator-toree/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-toree/commit/8d9e1e02
Tree: http://git-wip-us.apache.org/repos/asf/incubator-toree/tree/8d9e1e02
Diff: http://git-wip-us.apache.org/repos/asf/incubator-toree/diff/8d9e1e02

Branch: refs/heads/master
Commit: 8d9e1e02fdc34f59fafe3228726b5cc6a9265994
Parents: e0354f7
Author: Marius van Niekerk <ma...@gmail.com>
Authored: Thu Sep 22 19:58:16 2016 -0400
Committer: Marius van Niekerk <ma...@gmail.com>
Committed: Tue Sep 27 10:23:47 2016 -0400

----------------------------------------------------------------------
 .../kernel/interpreter/scala/ScalaInterpreterSpecific.scala      | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/8d9e1e02/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
----------------------------------------------------------------------
diff --git a/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala b/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
index b215d90..bd8f972 100644
--- a/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
+++ b/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
@@ -296,7 +296,7 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
       iMain.interpret("import org.apache.spark.SparkContext._")
 
       logger.debug("Adding the hack for the exception handling retrieval.")
-      iMain.bind("_exceptionHack", exceptionHack)
+      iMain.bind("_exceptionHack", classOf[ExceptionHack].getName, exceptionHack, List("@transient"))
     }
 
     this
@@ -439,4 +439,4 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
   */
 class ExceptionHack {
   var lastException: Throwable = _
-}
\ No newline at end of file
+}


[4/4] incubator-toree git commit: TOREE-341 Fixed exception stack traces getting lost.

Posted by ch...@apache.org.
TOREE-341 Fixed exception stack traces getting lost.

This is a rather ugly fix to address the issue caused by
https://issues.scala-lang.org/browse/SI-8935

The crux of the issue is that valueOfTerm returns None -- always

This introduces a small class that is bound into the REPL scope so that we
can modify its internal state and use that to retrieve values.

We can extend this to a more general case later on if needed.


Project: http://git-wip-us.apache.org/repos/asf/incubator-toree/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-toree/commit/7e947b4e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-toree/tree/7e947b4e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-toree/diff/7e947b4e

Branch: refs/heads/master
Commit: 7e947b4ea8876cc6050acd5e968760fa4241de6c
Parents: 1ea7b56
Author: Marius Van Niekerk <mn...@vm179.corp.maxpointinteractive.com>
Authored: Wed Sep 21 11:17:28 2016 -0400
Committer: Marius van Niekerk <ma...@gmail.com>
Committed: Tue Sep 27 10:23:47 2016 -0400

----------------------------------------------------------------------
 .../scala/ScalaInterpreterSpecific.scala        | 54 +++++++++++++++++---
 1 file changed, 46 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/7e947b4e/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
----------------------------------------------------------------------
diff --git a/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala b/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
index be729e0..6a31a55 100644
--- a/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
+++ b/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
@@ -36,6 +36,7 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
 
   private var iMain: IMain = _
   private var jLineCompleter: JLineCompletion = _
+  private val exceptionHack = new ExceptionHack()
 
   def _runtimeClassloader = {
     _thisClassloader
@@ -293,6 +294,9 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
       //   ADD IMPORTS generates too many classes, client is responsible for adding import
       logger.debug("Adding org.apache.spark.SparkContext._ to imports")
       iMain.interpret("import org.apache.spark.SparkContext._")
+
+      logger.debug("Adding the hack for the exception handling retrieval.")
+      iMain.bind("_exceptionHack", exceptionHack)
     }
 
     this
@@ -347,6 +351,20 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
     }
   }
 
+  private def retrieveLastException: Throwable = {
+    iMain.interpret("_exceptionHack.lastException = lastException")
+    exceptionHack.lastException
+  }
+
+  private def clearLastException(): Unit = {
+    iMain.directBind(
+      ExecutionExceptionName,
+      classOf[Throwable].getName,
+      null
+    )
+    exceptionHack.lastException = null
+  }
+
   protected def interpretMapToResultAndExecuteInfo(
     future: Future[(Results.Result, String)]
   ): Future[(Results.Result, Either[ExecuteOutput, ExecuteFailure])] = {
@@ -356,11 +374,12 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
       case (Results.Incomplete, output) => (Results.Incomplete, Left(output))
       case (Results.Aborted, output)    => (Results.Aborted, Right(null))
       case (Results.Error, output)      =>
+        val ex = Some(retrieveLastException)
         (
           Results.Error,
           Right(
             interpretConstructExecuteError(
-              read(ExecutionExceptionName),
+              ex,
               output
             )
           )
@@ -375,16 +394,24 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
     // Runtime error
     case Some(e) if e != null =>
       val ex = e.asInstanceOf[Throwable]
-      // Clear runtime error message
-      iMain.directBind(
-        ExecutionExceptionName,
-        classOf[Throwable].getName,
-        null
-      )
+      clearLastException()
+
+      // The scala REPL does a pretty good job of returning us a stack trace that is free from all the bits that the
+      // interpreter uses before it.
+      //
+      // The REPL emits its message as something like this, so trim off the first and last element
+      //
+      //    java.lang.ArithmeticException: / by zero
+      //    at failure(<console>:17)
+      //    at call_failure(<console>:19)
+      //    ... 40 elided
+
+      val formattedException = output.split("\n")
+
       ExecuteError(
         ex.getClass.getName,
         ex.getLocalizedMessage,
-        ex.getStackTrace.map(_.toString).toList
+        formattedException.slice(1, formattedException.size - 1).toList
       )
     // Compile time error, need to check internal reporter
     case _ =>
@@ -399,3 +426,14 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
         ExecuteError("Unknown", "Unable to retrieve error!", List())
   }
 }
+
+/**
+  * Due to a bug in the scala interpreter under scala 2.11 (SI-8935) with IMain.valueOfTerm we can hack around it by
+  * binding an instance of ExceptionHack into iMain and interpret the "_exceptionHack.lastException = lastException".
+  * This makes it possible to extract the exception.
+  *
+  * TODO: Revisit this once Scala 2.12 is released.
+  */
+class ExceptionHack {
+  var lastException: Throwable = _
+}
\ No newline at end of file


[2/4] incubator-toree git commit: Fixed test that tried to initialize without a kernel.

Posted by ch...@apache.org.
Fixed test that tried to initialize without a kernel.


Project: http://git-wip-us.apache.org/repos/asf/incubator-toree/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-toree/commit/0dc67018
Tree: http://git-wip-us.apache.org/repos/asf/incubator-toree/tree/0dc67018
Diff: http://git-wip-us.apache.org/repos/asf/incubator-toree/diff/0dc67018

Branch: refs/heads/master
Commit: 0dc67018ca358e013d57acabd6ac5a795425ac8e
Parents: 7e947b4
Author: Marius Van Niekerk <mn...@vm179.corp.maxpointinteractive.com>
Authored: Wed Sep 21 13:36:40 2016 -0400
Committer: Marius van Niekerk <ma...@gmail.com>
Committed: Tue Sep 27 10:23:47 2016 -0400

----------------------------------------------------------------------
 .../scala/integration/PostProcessorSpecForIntegration.scala | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/0dc67018/kernel/src/test/scala/integration/PostProcessorSpecForIntegration.scala
----------------------------------------------------------------------
diff --git a/kernel/src/test/scala/integration/PostProcessorSpecForIntegration.scala b/kernel/src/test/scala/integration/PostProcessorSpecForIntegration.scala
index 82223d3..8b392ad 100644
--- a/kernel/src/test/scala/integration/PostProcessorSpecForIntegration.scala
+++ b/kernel/src/test/scala/integration/PostProcessorSpecForIntegration.scala
@@ -19,10 +19,10 @@ package integration
 
 import java.io.OutputStream
 
-import org.apache.toree.kernel.api.KernelLike
+import org.apache.toree.kernel.api.Kernel
 import org.apache.toree.kernel.interpreter.scala.ScalaInterpreter
 import org.apache.toree.kernel.protocol.v5.magic.PostProcessor
-import org.apache.toree.utils.{MultiOutputStream, TaskManager}
+import org.apache.toree.utils.{MultiOutputStream}
 import org.scalatest.mock.MockitoSugar
 import org.scalatest.{BeforeAndAfter, FunSpec, Matchers}
 
@@ -37,12 +37,9 @@ class PostProcessorSpecForIntegration extends FunSpec with Matchers
     //       for performance improvements
     scalaInterpreter = new ScalaInterpreter {
       override protected val multiOutputStream = MultiOutputStream(List(mock[OutputStream], lastResultOut))
-
-      override protected def bindKernelVariable(kernel: KernelLike): Unit = { }
     }
 
-    // scalaInterpreter.start()
-    scalaInterpreter.init(mock[KernelLike])
+    scalaInterpreter.init(mock[Kernel])
 
     postProcessor = new PostProcessor(scalaInterpreter)
   }


[3/4] incubator-toree git commit: Ensure that that messages from retrieving the exception don't leak out.

Posted by ch...@apache.org.
Ensure that that messages from retrieving the exception don't leak out.


Project: http://git-wip-us.apache.org/repos/asf/incubator-toree/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-toree/commit/e0354f73
Tree: http://git-wip-us.apache.org/repos/asf/incubator-toree/tree/e0354f73
Diff: http://git-wip-us.apache.org/repos/asf/incubator-toree/diff/e0354f73

Branch: refs/heads/master
Commit: e0354f73b57968d60e1c5474b62b9fd6c4481597
Parents: 0dc6701
Author: Marius Van Niekerk <mn...@vm179.corp.maxpointinteractive.com>
Authored: Thu Sep 22 10:30:31 2016 -0400
Committer: Marius van Niekerk <ma...@gmail.com>
Committed: Tue Sep 27 10:23:47 2016 -0400

----------------------------------------------------------------------
 .../kernel/interpreter/scala/ScalaInterpreterSpecific.scala   | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-toree/blob/e0354f73/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
----------------------------------------------------------------------
diff --git a/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala b/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
index 6a31a55..b215d90 100644
--- a/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
+++ b/scala-interpreter/src/main/scala-2.11/org/apache/toree/kernel/interpreter/scala/ScalaInterpreterSpecific.scala
@@ -352,7 +352,9 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
   }
 
   private def retrieveLastException: Throwable = {
-    iMain.interpret("_exceptionHack.lastException = lastException")
+    iMain.beSilentDuring {
+      iMain.interpret("_exceptionHack.lastException = lastException")
+    }
     exceptionHack.lastException
   }
 
@@ -423,7 +425,8 @@ trait ScalaInterpreterSpecific extends SettingsProducerLike { this: ScalaInterpr
           "Compile Error", output, List()
         )
       else
-        ExecuteError("Unknown", "Unable to retrieve error!", List())
+        // May as capture the output here.  Could be useful
+        ExecuteError("Unknown Error", output, List())
   }
 }