mirror of https://github.com/sbt/sbt.git
improve error messages for cycles
This commit is contained in:
parent
36034612bc
commit
f55414355e
|
|
@ -176,9 +176,12 @@ object Project extends Init[Scope] with ProjectExtra
|
|||
ss.map(_ mapReferenced f)
|
||||
}
|
||||
def translateUninitialized[T](f: => T): T =
|
||||
try { f } catch { case u: Project.Uninitialized =>
|
||||
val msg = "Uninitialized reference to " + display(u.key) + " from " + display(u.refKey)
|
||||
throw new Uninitialized(u.key, u.refKey, msg)
|
||||
try { f } catch {
|
||||
case u: Project.Uninitialized =>
|
||||
val msg = "Uninitialized reference to " + display(u.key) + " from " + display(u.refKey)
|
||||
throw new Uninitialized(u.key, u.refKey, msg)
|
||||
case c: Dag.Cyclic =>
|
||||
throw new MessageOnlyException(c.getMessage)
|
||||
}
|
||||
|
||||
def delegates(structure: Load.BuildStructure, scope: Scope, key: AttributeKey[_]): Seq[ScopedKey[_]] =
|
||||
|
|
|
|||
|
|
@ -22,20 +22,31 @@ object Dag
|
|||
val finished = asSet(new java.util.LinkedHashSet[T])
|
||||
|
||||
def visitAll(nodes: Iterable[T]) = nodes foreach visit
|
||||
def visit(dag : T){
|
||||
if (!discovered(dag)) {
|
||||
discovered(dag) = true;
|
||||
visitAll(dependencies(dag));
|
||||
finished += dag;
|
||||
def visit(node : T){
|
||||
if (!discovered(node)) {
|
||||
discovered(node) = true;
|
||||
try { visitAll(dependencies(node)); } catch { case c: Cyclic => throw node :: c }
|
||||
finished += node;
|
||||
}
|
||||
else if(!finished(dag))
|
||||
throw new Cyclic(dag)
|
||||
else if(!finished(node))
|
||||
throw new Cyclic(node)
|
||||
}
|
||||
|
||||
visitAll(nodes);
|
||||
|
||||
finished.toList;
|
||||
}
|
||||
final class Cyclic(val value: Any) extends Exception("Cyclic reference involving " + value)
|
||||
final class Cyclic(val value: Any, val all: List[Any], val complete: Boolean)
|
||||
extends Exception( "Cyclic reference involving " + (if(complete) all.mkString(", ") else value) )
|
||||
{
|
||||
def this(value: Any) = this(value, value :: Nil, false)
|
||||
def ::(a: Any): Cyclic =
|
||||
if(complete)
|
||||
this
|
||||
else if(a == value)
|
||||
new Cyclic(value, all, true)
|
||||
else
|
||||
new Cyclic(value, a :: all, false)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue