Skip to content

Commit 034d519

Browse files
committed
Attempt to unwrap the exception that may be thrown in the interpreted scripts
1 parent 1490cc2 commit 034d519

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

scala-console/src/main/scala-3/dotty/tools/repl/SCIMain.scala

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package dotty.tools.repl
33
import dotty.tools.dotc.core.StdNames.str
44

55
import java.io.PrintStream
6-
import java.lang.reflect.Method
6+
import java.lang.reflect.{InvocationTargetException, Method}
77
import scala.annotation.tailrec
88
import scala.util.control.NonFatal
99
import scala.util.{Failure, Success, Try}
@@ -55,13 +55,23 @@ class SCIMain(out: PrintStream, loader: ClassLoader) {
5555
else
5656
SCResults.Success
5757
case Failure(ex) =>
58-
if wasCausedByImageJMacroAbort(ex) then
59-
out.println(s"WARNING: Detected ImageJ's \"$IMAGEJ_MACRO_CANCELED\" request. Stopping script execution.")
60-
SCResults.Success
61-
else
62-
// ex.printStackTrace()
63-
// ex.printStackTrace(out)
64-
SCResults.Error
58+
ex match {
59+
case ex1 if wasCausedByImageJMacroAbort(ex1) =>
60+
out.println(s"WARNING: Detected ImageJ's \"$IMAGEJ_MACRO_CANCELED\" request. Stopping script execution.")
61+
SCResults.Success
62+
// Attempt to unwrap the exception that may be thrown in the interpreted scripts, skip the wrapping
63+
case e1: InvocationTargetException =>
64+
e1.getCause match {
65+
case ex2: ExceptionInInitializerError =>
66+
Option(ex2.getCause).foreach(_.printStackTrace(out))
67+
case _ =>
68+
// ???
69+
}
70+
SCResults.Error
71+
case _ =>
72+
// ???
73+
SCResults.Error
74+
}
6575
}
6676

6777
private def evalToMethod(script: String): Option[Method] = {

0 commit comments

Comments
 (0)