mirror of https://github.com/sbt/sbt.git
Slightly better error messages from plugin
This commit is contained in:
parent
e688828f7a
commit
6e27a7fc6e
|
|
@ -1,5 +1,7 @@
|
|||
package coursier
|
||||
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
|
||||
sealed abstract class ResolutionError extends Product with Serializable {
|
||||
def cause: Option[Throwable] = this match {
|
||||
case ResolutionError.MaximumIterationsReached => None
|
||||
|
|
@ -20,15 +22,8 @@ sealed abstract class ResolutionError extends Product with Serializable {
|
|||
case ResolutionError.Conflicts(description) =>
|
||||
description
|
||||
|
||||
case ResolutionError.MetadataDownloadErrors(errors) =>
|
||||
s"Encountered ${errors.length} error(s) in dependency resolution:\n" +
|
||||
errors.map {
|
||||
case (dep, errs) =>
|
||||
s" ${dep.module}:${dep.version}:\n" +
|
||||
errs
|
||||
.map(" " + _.replace("\n", " \n"))
|
||||
.mkString("\n")
|
||||
}.mkString("\n")
|
||||
case err: ResolutionError.MetadataDownloadErrors =>
|
||||
err.description()
|
||||
|
||||
case err: ResolutionError.DownloadErrors =>
|
||||
err.description(verbose = true)
|
||||
|
|
@ -47,7 +42,49 @@ object ResolutionError {
|
|||
case class UnknownException(ex: Throwable) extends ResolutionError
|
||||
case class UnknownDownloadException(ex: Throwable) extends ResolutionError
|
||||
case class Conflicts(description: String) extends ResolutionError
|
||||
case class MetadataDownloadErrors(errors: Seq[(Dependency, Seq[String])]) extends ResolutionError
|
||||
|
||||
case class MetadataDownloadErrors(errors: Seq[(Dependency, Seq[String])]) extends ResolutionError {
|
||||
def description(): String = {
|
||||
|
||||
def grouped(errs: Seq[String]) =
|
||||
errs
|
||||
.map { s =>
|
||||
val idx = s.indexOf(": ")
|
||||
if (idx >= 0)
|
||||
(s.take(idx), s.drop(idx + ": ".length))
|
||||
else
|
||||
("", s)
|
||||
}
|
||||
.groupBy(_._1)
|
||||
.mapValues(_.map(_._2))
|
||||
.toVector
|
||||
.sortBy(_._1)
|
||||
|
||||
val lines = new ArrayBuffer[String]
|
||||
|
||||
lines += s"Encountered ${errors.length} error(s) in dependency resolution:"
|
||||
|
||||
for ((dep, errs) <- errors) {
|
||||
lines += s" ${dep.module}:${dep.version}:"
|
||||
|
||||
for ((type0, errs0) <- grouped(errs))
|
||||
if (type0.isEmpty)
|
||||
for (err <- errs0)
|
||||
lines += s" $err"
|
||||
else
|
||||
errs0 match {
|
||||
case Seq(err) =>
|
||||
lines += s" $type0: $err"
|
||||
case _ =>
|
||||
lines += s" $type0:"
|
||||
for (err <- errs0)
|
||||
lines += s" $err"
|
||||
}
|
||||
}
|
||||
|
||||
lines.mkString("\n")
|
||||
}
|
||||
}
|
||||
|
||||
case class DownloadErrors(errors: Seq[FileError]) extends ResolutionError {
|
||||
|
||||
|
|
|
|||
|
|
@ -439,8 +439,10 @@ object Tasks {
|
|||
}
|
||||
}
|
||||
|
||||
val internalRepositories = Seq(globalPluginsRepo, interProjectRepo)
|
||||
|
||||
val repositories =
|
||||
Seq(globalPluginsRepo, interProjectRepo) ++
|
||||
internalRepositories ++
|
||||
sourceRepositories0 ++
|
||||
resolvers.flatMap { resolver =>
|
||||
FromSbt.repository(
|
||||
|
|
@ -528,9 +530,21 @@ object Tasks {
|
|||
).throwException()
|
||||
}
|
||||
|
||||
if (res.errors.nonEmpty)
|
||||
ResolutionError.MetadataDownloadErrors(res.errors)
|
||||
if (res.errors.nonEmpty) {
|
||||
val internalRepositoriesLen = internalRepositories.length
|
||||
val errors =
|
||||
if (repositories.length > internalRepositoriesLen)
|
||||
// drop internal repository errors
|
||||
res.errors.map {
|
||||
case (dep, errs) =>
|
||||
dep -> errs.drop(internalRepositoriesLen)
|
||||
}
|
||||
else
|
||||
res.errors
|
||||
|
||||
ResolutionError.MetadataDownloadErrors(errors)
|
||||
.throwException()
|
||||
}
|
||||
|
||||
if (verbosityLevel >= 0)
|
||||
log.info(s"Resolved ${projectDescription(currentProject)} dependencies")
|
||||
|
|
|
|||
Loading…
Reference in New Issue