From 758380979e8974d4ca8235835da13bcf4b7fad75 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Wed, 4 Aug 2010 19:41:11 -0400 Subject: [PATCH] command error handling --- main/Main.scala | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/main/Main.scala b/main/Main.scala index e5cf25b04..cc5012b2d 100644 --- a/main/Main.scala +++ b/main/Main.scala @@ -39,7 +39,12 @@ class xMain extends xsbti.AppMain new Reboot(app.scalaProvider.version, state.commands, app.id, state.configuration.baseDirectory) } } - def next(state: State): State = state.process(process) + def next(state: State): State = + ErrorHandling.wideConvert { state.process(process) } match + { + case Right(s) => s + case Left(t) => Commands.handleException(t, state) + } def process(command: String, state: State): State = { val in = Input(command, None) @@ -193,10 +198,17 @@ object Commands loadCommand(in.arguments, s.configuration, false, "sbt.Project") match // TODO: classOf[Project].getName when ready { case Right(Seq(newValue)) => runExitHooks(s).copy(project = newValue)() - case Left(e) => e.printStackTrace; System.err.println(e.toString); s.fail // TODO: log instead of print + case Left(e) => handleException(e, s) } } + def handleException(e: Throwable, s: State): State = { + // TODO: log instead of print + e.printStackTrace + System.err.println(e.toString) + s.fail + } + def runExitHooks(s: State): State = { ExitHooks.runExitHooks(s.exitHooks.toSeq) s.copy()(exitHooks = Set.empty)