mirror of
https://github.com/sbt/sbt.git
synced 2026-08-29 01:24:09 +02:00
Add better error message if run fails
It is possible with the new layering strategies that tests may fail if a java package private class is accessed across classloader layers. This will result in an IllegalAccessError that is hard to debug. With this commit, I add an error message that will be displayed if run throws an IllegalAccessError that suggests that the user try the ScalaInstance layering strategy or the flat layering strategy.
This commit is contained in:
@@ -122,9 +122,25 @@ final class TestRunner(
|
||||
val results = new scala.collection.mutable.ListBuffer[Event]
|
||||
val handler = new EventHandler { def handle(e: Event): Unit = { results += e } }
|
||||
val loggers: Vector[ContentLogger] = listeners.flatMap(_.contentLogger(testDefinition))
|
||||
def errorEvents(e: Throwable): Array[sbt.testing.Task] = {
|
||||
val taskDef = testTask.taskDef
|
||||
val event = new Event {
|
||||
val status = Status.Error
|
||||
val throwable = new OptionalThrowable(e)
|
||||
val fullyQualifiedName = taskDef.fullyQualifiedName
|
||||
val selector = new TestSelector(name)
|
||||
val fingerprint = taskDef.fingerprint
|
||||
val duration = -1L
|
||||
}
|
||||
results += event
|
||||
Array.empty
|
||||
}
|
||||
val nestedTasks =
|
||||
try testTask.execute(handler, loggers.map(_.log).toArray)
|
||||
finally {
|
||||
catch {
|
||||
case NonFatal(e) => errorEvents(e)
|
||||
case e: IllegalAccessError => errorEvents(e)
|
||||
} finally {
|
||||
loggers.foreach(_.flush())
|
||||
}
|
||||
val event = TestEvent(results)
|
||||
|
||||
Reference in New Issue
Block a user