Skip to content

Commit

Permalink
fail fast if repositories cannot be resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek authored and tgodzik committed Dec 12, 2023
1 parent 98e7056 commit 67ec987
Showing 1 changed file with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package scala.meta.internal.metals

import java.net.UnknownHostException
import java.nio.file.Path
import java.util.concurrent.TimeUnit
import java.util.concurrent.TimeoutException
Expand All @@ -17,6 +18,7 @@ import scala.meta.io.AbsolutePath

import coursier.Fetch
import coursier.Repositories
import coursier.cache.ArtifactError
import coursier.core.Classifier
import coursier.core.Dependency
import coursier.core.Module
Expand Down Expand Up @@ -56,9 +58,20 @@ object JarSourcesProvider {
dependencies.map { dep =>
fetchDependencySources(dep)
.recover { case error: CoursierError =>
scribe.warn(
s"Could not fetch dependency sources for $dep, error: $error"
)
Option(error.getCause()).map(e => (e, e.getCause())) match {
case Some(
(
_: ArtifactError.DownloadError,
e: UnknownHostException,
)
) =>
// Fail all if repositories cannot be resolved, e.g. no internet connection.
throw e
case _ =>
scribe.warn(
s"Could not fetch dependency sources for $dep, error: $error"
)
}
Nil
}
}
Expand All @@ -67,6 +80,9 @@ object JarSourcesProvider {
case _: TimeoutException =>
scribe.warn(s"Timeout when fetching dependency sources.")
Nil
case e: UnknownHostException =>
scribe.warn(s"Repository `${e.getMessage()}` is not available.")
Nil
case NonFatal(e) =>
scribe.warn(s"Could not fetch dependency sources, error: $e.")
Nil
Expand All @@ -83,6 +99,8 @@ object JarSourcesProvider {
filename match {
case sbtRegex(versionStr) =>
Try(SemVer.Version.fromString(versionStr)) match {
// Since `SemVer.Version.fromString` might be able to parse strings, that are not versions,
// we check if the result version is a correct parse of the input string.
case Success(version) if version.toString == versionStr =>
val module = Module(
Organization("org.scala-sbt"),
Expand Down Expand Up @@ -133,7 +151,7 @@ object JarSourcesProvider {
.addClassifiers(Classifier.sources)
.future()
.map(_.map(_.toPath()).toList)
.withTimeout(5, TimeUnit.MINUTES)
.withTimeout(1, TimeUnit.MINUTES)
}

}

0 comments on commit 67ec987

Please sign in to comment.