From f340cda164d34c5b8855863c4456b4fbaf34a484 Mon Sep 17 00:00:00 2001 From: Alexandre Archambault Date: Wed, 5 Sep 2018 15:08:51 +0200 Subject: [PATCH] Check and report errors during predef (#217) --- .../main/scala/almond/ScalaInterpreter.scala | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/modules/scala/scala-interpreter/src/main/scala/almond/ScalaInterpreter.scala b/modules/scala/scala-interpreter/src/main/scala/almond/ScalaInterpreter.scala index 3bc2037d9..7fe8f77d6 100644 --- a/modules/scala/scala-interpreter/src/main/scala/almond/ScalaInterpreter.scala +++ b/modules/scala/scala-interpreter/src/main/scala/almond/ScalaInterpreter.scala @@ -288,8 +288,24 @@ final class ScalaInterpreter( else predef - val stmts = Parsers.split(code).get.get.value - ammInterp0.processLine(code, stmts, -1, silent = true, () => ()) + def handlePredef(): Unit = { + val stmts = Parsers.split(code).get.get.value + val predefRes = ammInterp0.processLine(code, stmts, 9999999, silent = false, () => ()) + Repl.handleOutput(ammInterp0, predefRes) + predefRes match { + case Res.Success(_) => + case Res.Failure(msg) => + log.error(s"Error while running predef: $msg") + sys.exit(1) + case Res.Exception(t, msg) => + log.error(s"Caught exception while running predef ($msg)", t) + case Res.Skip => + case Res.Exit(v) => + log.warn(s"Ignoring exit request from predef (exit value: $v)") + } + } + + handlePredef() log.info("Ammonite interpreter ok")