From 64618fe56af6814d19f6c2f20fbe17e31fd54d83 Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Thu, 10 Jun 2010 21:25:37 -0400 Subject: [PATCH] wideConvert lets the serious errors pass through, use it in Execute --- tasks/Execute.scala | 13 +++++-------- util/control/ErrorHandling.scala | 11 +++++++++-- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/tasks/Execute.scala b/tasks/Execute.scala index 917922667..3189bc079 100644 --- a/tasks/Execute.scala +++ b/tasks/Execute.scala @@ -3,8 +3,7 @@ */ package sbt -// TODO: Incomplete needs to be parameterized with A[_] and have val node - +import ErrorHandling.wideConvert import Types._ import Execute._ @@ -215,12 +214,10 @@ final class Execute[A[_] <: AnyRef](checkCycles: Boolean)(implicit view: A ~> No * This returns a Completed instance, which contains the post-processing to perform after the result is retrieved from the Strategy.*/ def work[T](node: A[T], f: => Either[A[T], T])(implicit strategy: Strategy): Completed = { - val result = - try { Right(f) } - catch { - case i: Incomplete => Left(i) - case e => Left( Incomplete(Incomplete.Error, directCause = Some(e)) ) - } + val result = wideConvert(f).left.map { + case i: Incomplete => i + case e => Incomplete(Incomplete.Error, directCause = Some(e)) + } completed { result match { case Left(i) => retire(node, Inc(i)) diff --git a/util/control/ErrorHandling.scala b/util/control/ErrorHandling.scala index 98c1b1a73..f4d42993b 100644 --- a/util/control/ErrorHandling.scala +++ b/util/control/ErrorHandling.scala @@ -7,10 +7,17 @@ object ErrorHandling { def translate[T](msg: => String)(f: => T) = try { f } - catch { case e => throw new TranslatedException(msg + e.toString, e) } + catch { case e: Exception => throw new TranslatedException(msg + e.toString, e) } + def wideConvert[T](f: => T): Either[Throwable, T] = try { Right(f) } - catch { case e => Left(e) } // TODO: restrict type of e + catch + { + case ex @ (_: Exception | _: StackOverflowError) => Left(ex) + case err @ (_: ThreadDeath | _: VirtualMachineError) => throw err + case x => Left(x) + } + def convert[T](f: => T): Either[Exception, T] = try { Right(f) } catch { case e: Exception => Left(e) }