Skip to content

Commit

Permalink
Error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
dbtsai committed Jun 8, 2018
1 parent 631ef48 commit 96e87c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,28 @@ class SparkILoop(in0: Option[BufferedReader], out: JPrintWriter)
"import org.apache.spark.sql.functions._"
)

def initializeSpark(): Unit = savingReplayStack {
// `savingReplayStack` removes the commands from session history.
initializationCommands.foreach(intp quietRun _)
def initializeSpark(): Unit = {
if (!intp.reporter.hasErrors) {
// `savingReplayStack` removes the commands from session history.
savingReplayStack {
initializationCommands.foreach(intp quietRun _)
}
} else {
throw new RuntimeException(s"Scala $versionString interpreter encountered " +
"errors during initialization")
}
}

/** Print a welcome message */
override def printWelcome() {
// Before Scala 2.11.9, `printWelcome()` will be the last thing to be called,
// so Scala REPL and Spark will be initialized before `printWelcome()`.
// After Scala 2.11.9, `printWelcome()` will be the first thing to be called,
// as a result, Scala REPL and Spark will be initialized in `printWelcome()`.
if (!isInitializeComplete) {
intp.initializeSynchronous()
}

import org.apache.spark.SPARK_VERSION
echo("""Welcome to
____ __
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import scala.tools.nsc.Settings
import scala.tools.nsc.interpreter._

class SparkILoopInterpreter(settings: Settings, out: JPrintWriter, initializeSpark: () => Unit)
extends IMain(settings, out) { self =>
extends IMain(settings, out) { self =>

/**
* We override `initializeSynchronous` to initialize Spark *after* `intp` is properly initialized
Expand All @@ -34,8 +34,10 @@ class SparkILoopInterpreter(settings: Settings, out: JPrintWriter, initializeSpa
* See the discussion in Scala community https://github.com/scala/bug/issues/10913 for detail.
*/
override def initializeSynchronous(): Unit = {
super.initializeSynchronous()
initializeSpark()
if (!isInitializeComplete) {
super.initializeSynchronous()
initializeSpark()
}
}

override lazy val memberHandlers = new {
Expand Down

0 comments on commit 96e87c2

Please sign in to comment.