From c0b74d9bcdf3e9d4601b6057dd8ddfd556ef757c Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 1 Nov 2010 20:30:22 +0000 Subject: Don't call exit from MainGenericRunner in a way... Don't call exit from MainGenericRunner in a way which is impossible to avoid. Closes #3901, no review. --- .../scala/tools/nsc/MainGenericRunner.scala | 41 +++++++++++++--------- 1 file changed, 24 insertions(+), 17 deletions(-) (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/MainGenericRunner.scala b/src/compiler/scala/tools/nsc/MainGenericRunner.scala index 96d6846d64..695ce090dc 100644 --- a/src/compiler/scala/tools/nsc/MainGenericRunner.scala +++ b/src/compiler/scala/tools/nsc/MainGenericRunner.scala @@ -21,16 +21,19 @@ import Properties.{ versionString, copyrightString } * or interactive entry. */ object MainGenericRunner { + def errorFn(ex: Throwable): Boolean = errorFn(ex.toString) + def errorFn(str: String): Boolean = { + Console println str + false + } + def main(args: Array[String]) { - def errorFn(str: String) = Console println str - def exitSuccess: Nothing = exit(0) - def exitFailure(msg: Any = null): Nothing = { - if (msg != null) errorFn(msg.toString) + if (!process(args)) exit(1) - } - def exitCond(b: Boolean): Nothing = if (b) exitSuccess else exitFailure(null) + } - val command = new GenericRunnerCommand(args.toList, errorFn _) + def process(args: Array[String]): Boolean = { + val command = new GenericRunnerCommand(args.toList, (x: String) => errorFn(x)) import command.settings def sampleCompiler = new Global(settings) // def so its not created unless needed @@ -64,12 +67,13 @@ object MainGenericRunner { */ val fullArgs = command.thingToRun.toList ::: command.arguments - exitCond(ScriptRunner.runCommand(settings, combinedCode, fullArgs)) + return ScriptRunner.runCommand(settings, combinedCode, fullArgs) } else command.thingToRun match { case None => - // Questionably, we start the interpreter when there are no arguments. + // We start the repl when no arguments are given. new InterpreterLoop main settings + true // not actually reached in general case Some(thingToRun) => val isObjectName = @@ -80,18 +84,21 @@ object MainGenericRunner { } if (isObjectName) - try ObjectRunner.run(classpath, thingToRun, command.arguments) + try { + ObjectRunner.run(classpath, thingToRun, command.arguments) + true + } catch { - case e @ (_: ClassNotFoundException | _: NoSuchMethodException) => exitFailure(e) - case e: InvocationTargetException => - e.getCause.printStackTrace - exitFailure() + case e @ (_: ClassNotFoundException | _: NoSuchMethodException) => errorFn(e) + case e: InvocationTargetException => errorFn(e.getCause) } else - try exitCond(ScriptRunner.runScript(settings, thingToRun, command.arguments)) + try { + ScriptRunner.runScript(settings, thingToRun, command.arguments) + } catch { - case e: IOException => exitFailure(e.getMessage) - case e: SecurityException => exitFailure(e) + case e: IOException => errorFn(e.getMessage) + case e: SecurityException => errorFn(e) } } } -- cgit v1.2.3