clean up build definition exceptions and messages

This commit is contained in:
Mark Harrah 2011-04-03 21:08:06 -04:00
parent d63398534c
commit a5f3e1b839
4 changed files with 23 additions and 7 deletions

View File

@ -94,7 +94,7 @@ final class Eval(optionsNoncp: Seq[String], classpath: Seq[File], mkReporter: Se
}
compile(run.namerPhase)
checkError("Type error.")
checkError("Type error in expression")
val tpe = atPhase(run.typerPhase.next) { (new TypeExtractor).getType(unit.body) }
(tpe, load(dir, moduleName))
@ -163,7 +163,7 @@ final class Eval(optionsNoncp: Seq[String], classpath: Seq[File], mkReporter: Se
val tpeParser = new syntaxAnalyzer.UnitParser(mkUnit("<expected-type>", DefaultStartLine, tpe))
val tpt0: Tree = tpeParser.typ()
tpeParser.accept(EOF)
checkError("Error parsing type.")
checkError("Error parsing expression type.")
tpt0
}
private[this] def parseImports(imports: EvalImports): Seq[Tree] =
@ -173,7 +173,7 @@ final class Eval(optionsNoncp: Seq[String], classpath: Seq[File], mkReporter: Se
val parser = new syntaxAnalyzer.UnitParser(importUnit)
val trees: Seq[Tree] = parser.importClause()
parser.accept(EOF)
checkError("Error parsing imports.")
checkError("Error parsing imports for expression.")
trees
}

View File

@ -73,7 +73,11 @@ object EvaluateConfigurations
def evaluateSetting(eval: Eval, name: String, imports: Seq[(String,Int)], expression: String, line: Int): Setting[_] =
{
val result = eval.eval(expression, imports = new EvalImports(imports, name), srcName = name, tpeName = Some("sbt.Project.Setting[_]"), line = line)
val result = try {
eval.eval(expression, imports = new EvalImports(imports, name), srcName = name, tpeName = Some("sbt.Project.Setting[_]"), line = line)
} catch {
case e: sbt.compiler.EvalException => throw new MessageOnlyException(e.getMessage)
}
result.value.asInstanceOf[Setting[_]]
}
private[this] def fstS(f: String => Boolean): ((String,Int)) => Boolean = { case (s,i) => f(s) }
@ -570,8 +574,10 @@ object Load
def build(classpath: Seq[File], sources: Seq[File], target: File, compilers: Compilers, log: Logger): (Inputs, inc.Analysis) =
{
val inputs = Compiler.inputs(classpath, sources, target, Nil, Nil, Compiler.DefaultMaxErrors)(compilers, log)
val analysis = Compiler(inputs, log)
val inputs = Compiler.inputs(classpath, sources, target, Nil, Nil, Compiler.DefaultMaxErrors, CompileOrder.Mixed)(compilers, log)
val analysis =
try { Compiler(inputs, log) }
catch { case _: xsbti.CompileFailed => throw new NoMessageException } // compiler already logged errors
(inputs, analysis)
}

View File

@ -332,7 +332,10 @@ object BuiltinCommands
{
e match
{
case i: Incomplete => () // already handled by evaluateTask
case _: Incomplete => () // already handled by evaluateTask
case _: NoMessageException => ()
case _: MessageOnlyException =>
log.error(e.toString)
case _ =>
log.trace(e)
log.error(e.toString)

View File

@ -0,0 +1,7 @@
/* sbt -- Simple Build Tool
* Copyright 2011 Mark Harrah
*/
package sbt
final class MessageOnlyException(override val toString: String) extends RuntimeException(toString)
final class NoMessageException extends RuntimeException