From f186d50dafbb0a0311103ed5f697e4f70e1a913a Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Thu, 10 Dec 2009 21:04:51 -0500 Subject: [PATCH] Improving launcher error handling... --- launch/Boot.scala | 8 ++++---- launch/Create.scala | 6 +++--- launch/Exceptions.scala | 6 ++++++ launch/LaunchConfiguration.scala | 6 +----- launch/Pre.scala | 4 +++- 5 files changed, 17 insertions(+), 13 deletions(-) create mode 100644 launch/Exceptions.scala diff --git a/launch/Boot.scala b/launch/Boot.scala index 2cc17d56b..81bba43d7 100644 --- a/launch/Boot.scala +++ b/launch/Boot.scala @@ -15,16 +15,16 @@ object Boot try { Launch(args.toList) } catch { - case b: BootException => errorAndExit(b) + case b: BootException => errorAndExit(b.toString) case e => e.printStackTrace - errorAndExit(e) + errorAndExit(Pre.prefixError(e.toString)) } 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) } } diff --git a/launch/Create.scala b/launch/Create.scala index 61ff779c9..20f644818 100644 --- a/launch/Create.scala +++ b/launch/Create.scala @@ -10,12 +10,12 @@ object Initialize { SimpleReader.readLine(promptCreate + " (y/N" + (if(enableQuick) "/s" else "") + ") ") match { - case None => error("") + case None => declined("") case Some(line) => line.toLowerCase match { case "y" | "yes" => process(file, spec, _.create) - case "n" | "no" | "" => error("") + case "n" | "no" | "" => declined("") case "s" => process(file, spec, _.quick) } } @@ -41,7 +41,7 @@ object Initialize { case set: SetProperty => properties.setProperty(name, set.value) 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 { case None => noValue diff --git a/launch/Exceptions.scala b/launch/Exceptions.scala new file mode 100644 index 000000000..7ceca5d5b --- /dev/null +++ b/launch/Exceptions.scala @@ -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) diff --git a/launch/LaunchConfiguration.scala b/launch/LaunchConfiguration.scala index fbfc77297..0b3236048 100644 --- a/launch/LaunchConfiguration.scala +++ b/launch/LaunchConfiguration.scala @@ -100,8 +100,4 @@ object LogLevel extends Enumeration def apply(s: String): Logging = new Logging(toValue(s)) } -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 \ No newline at end of file +final class AppConfiguration(val arguments: Array[String], val baseDirectory: File, val provider: xsbti.AppProvider) extends xsbti.AppConfiguration \ No newline at end of file diff --git a/launch/Pre.scala b/launch/Pre.scala index 703bf109c..11ca3d856 100644 --- a/launch/Pre.scala +++ b/launch/Pre.scala @@ -12,7 +12,9 @@ object Pre def assert(condition: Boolean, msg: => String): Unit = if (!condition) throw new AssertionError(msg) def assert(condition: Boolean): Unit = assert(condition, "Assertion failed") 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 toArray[T](list: List[T]) = {