Skip to content

Commit 96e87c2

Browse files
committed
Error handling
1 parent 631ef48 commit 96e87c2

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

repl/scala-2.11/src/main/scala/org/apache/spark/repl/SparkILoop.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,28 @@ class SparkILoop(in0: Option[BufferedReader], out: JPrintWriter)
7373
"import org.apache.spark.sql.functions._"
7474
)
7575

76-
def initializeSpark(): Unit = savingReplayStack {
77-
// `savingReplayStack` removes the commands from session history.
78-
initializationCommands.foreach(intp quietRun _)
76+
def initializeSpark(): Unit = {
77+
if (!intp.reporter.hasErrors) {
78+
// `savingReplayStack` removes the commands from session history.
79+
savingReplayStack {
80+
initializationCommands.foreach(intp quietRun _)
81+
}
82+
} else {
83+
throw new RuntimeException(s"Scala $versionString interpreter encountered " +
84+
"errors during initialization")
85+
}
7986
}
8087

8188
/** Print a welcome message */
8289
override def printWelcome() {
90+
// Before Scala 2.11.9, `printWelcome()` will be the last thing to be called,
91+
// so Scala REPL and Spark will be initialized before `printWelcome()`.
92+
// After Scala 2.11.9, `printWelcome()` will be the first thing to be called,
93+
// as a result, Scala REPL and Spark will be initialized in `printWelcome()`.
94+
if (!isInitializeComplete) {
95+
intp.initializeSynchronous()
96+
}
97+
8398
import org.apache.spark.SPARK_VERSION
8499
echo("""Welcome to
85100
____ __

repl/scala-2.11/src/main/scala/org/apache/spark/repl/SparkILoopInterpreter.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import scala.tools.nsc.Settings
2222
import scala.tools.nsc.interpreter._
2323

2424
class SparkILoopInterpreter(settings: Settings, out: JPrintWriter, initializeSpark: () => Unit)
25-
extends IMain(settings, out) { self =>
25+
extends IMain(settings, out) { self =>
2626

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

4143
override lazy val memberHandlers = new {

0 commit comments

Comments
 (0)