Improving launcher error handling...

This commit is contained in:
Mark Harrah 2009-12-10 21:04:51 -05:00
parent 14db8c2079
commit f186d50daf
5 changed files with 17 additions and 13 deletions

View File

@ -15,16 +15,16 @@ object Boot
try { Launch(args.toList) } try { Launch(args.toList) }
catch catch
{ {
case b: BootException => errorAndExit(b) case b: BootException => errorAndExit(b.toString)
case e => case e =>
e.printStackTrace e.printStackTrace
errorAndExit(e) errorAndExit(Pre.prefixError(e.toString))
} }
System.exit(0) System.exit(0)
} }
private def errorAndExit(e: Throwable) private def errorAndExit(msg: String)
{ {
System.out.println("Error during sbt execution: " + e.toString) System.out.println(msg)
System.exit(1) System.exit(1)
} }
} }

View File

@ -10,12 +10,12 @@ object Initialize
{ {
SimpleReader.readLine(promptCreate + " (y/N" + (if(enableQuick) "/s" else "") + ") ") match SimpleReader.readLine(promptCreate + " (y/N" + (if(enableQuick) "/s" else "") + ") ") match
{ {
case None => error("") case None => declined("")
case Some(line) => case Some(line) =>
line.toLowerCase match line.toLowerCase match
{ {
case "y" | "yes" => process(file, spec, _.create) case "y" | "yes" => process(file, spec, _.create)
case "n" | "no" | "" => error("") case "n" | "no" | "" => declined("")
case "s" => process(file, spec, _.quick) case "s" => process(file, spec, _.quick)
} }
} }
@ -41,7 +41,7 @@ object Initialize
{ {
case set: SetProperty => properties.setProperty(name, set.value) case set: SetProperty => properties.setProperty(name, set.value)
case prompt: PromptProperty => case prompt: PromptProperty =>
def noValue = error("No value provided for " + prompt.label) def noValue = declined("No value provided for " + prompt.label)
SimpleReader.readLine(prompt.label + prompt.default.toList.map(" [" + _ + "]").mkString + ": ") match SimpleReader.readLine(prompt.label + prompt.default.toList.map(" [" + _ + "]").mkString + ": ") match
{ {
case None => noValue case None => noValue

6
launch/Exceptions.scala Normal file
View File

@ -0,0 +1,6 @@
package xsbt.boot
// The exception to use when an error occurs at the launcher level (and not a nested exception).
// This indicates overrides toString because the exception class name is not needed to understand
// the error message.
class BootException(override val toString: String) extends RuntimeException(toString)

View File

@ -101,7 +101,3 @@ object LogLevel extends Enumeration
} }
final class AppConfiguration(val arguments: Array[String], val baseDirectory: File, val provider: xsbti.AppProvider) extends xsbti.AppConfiguration final class AppConfiguration(val arguments: Array[String], val baseDirectory: File, val provider: xsbti.AppProvider) extends xsbti.AppConfiguration
// The exception to use when an error occurs at the launcher level (and not a nested exception).
// This indicates overrides toString because the exception class name is not needed to understand
// the error message.
class BootException(override val toString: String) extends RuntimeException

View File

@ -12,7 +12,9 @@ object Pre
def assert(condition: Boolean, msg: => String): Unit = if (!condition) throw new AssertionError(msg) def assert(condition: Boolean, msg: => String): Unit = if (!condition) throw new AssertionError(msg)
def assert(condition: Boolean): Unit = assert(condition, "Assertion failed") def assert(condition: Boolean): Unit = assert(condition, "Assertion failed")
def require(condition: Boolean, msg: => String): Unit = if (!condition) throw new IllegalArgumentException(msg) def require(condition: Boolean, msg: => String): Unit = if (!condition) throw new IllegalArgumentException(msg)
def error(msg: String): Nothing = throw new BootException(msg) def error(msg: String): Nothing = throw new BootException(prefixError(msg))
def declined(msg: String): Nothing = throw new BootException(msg)
def prefixError(msg: String): String = "Error during sbt execution: " + msg
def toBoolean(s: String) = java.lang.Boolean.parseBoolean(s) def toBoolean(s: String) = java.lang.Boolean.parseBoolean(s)
def toArray[T](list: List[T]) = def toArray[T](list: List[T]) =
{ {