bazeltools / bazel-deps

Generate bazel dependencies for maven artifacts
MIT License
250 stars 122 forks source link

Invalid resolver URLs are not handled gracefully #207

Open aherrmann opened 5 years ago

aherrmann commented 5 years ago

bazel-deps does not handle invalid resolver URLs gracefully. For example, modifying dependencies.yaml in this repository as follows

diff --git a/dependencies.yaml b/dependencies.yaml
index 27ac8a8..fb0404c 100644
--- a/dependencies.yaml
+++ b/dependencies.yaml
@@ -5,7 +5,7 @@ options:
   resolvers:
     - id: "mavencentral"
       type: "default"
-      url: https://repo.maven.apache.org/maven2/
+      url: https://repo.maven.apache.org/maven
   strictVisibility: true
   transitivity: runtime_deps
   versionConflictPolicy: highest

and running bazel-deps on its own repository generates the following error message:

$ bazel run //:parse -- generate --repo-root $PWD --sha-file 3rdparty/workspace.bzl --deps dependencies.yaml
...
[main] ERROR MakeDeps - resolution and sha collection failed
java.lang.IllegalArgumentException: requirement failed: MavenCoordinate(MavenGroup(org.eclipse.aether),MavenArtifactId(aether-impl,jar,None),Version(1.1.0))
        at scala.Predef$.require(Predef.scala:224)
        at com.github.johnynek.bazel_deps.MakeDeps$$anonfun$resolve$1$$anonfun$apply$2$$anonfun$apply$3.apply(MakeDeps.scala:127)
        at com.github.johnynek.bazel_deps.MakeDeps$$anonfun$resolve$1$$anonfun$apply$2$$anonfun$apply$3.apply(MakeDeps.scala:127)
        at scala.collection.Iterator$class.foreach(Iterator.scala:891)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1334)
        at scala.collection.MapLike$DefaultKeySet.foreach(MapLike.scala:174)
        at com.github.johnynek.bazel_deps.MakeDeps$$anonfun$resolve$1$$anonfun$apply$2.apply(MakeDeps.scala:127)
        at com.github.johnynek.bazel_deps.MakeDeps$$anonfun$resolve$1$$anonfun$apply$2.apply(MakeDeps.scala:126)
        at cats.ApplicativeError$class.catchNonFatal(ApplicativeError.scala:138)
        at com.github.johnynek.bazel_deps.CoursierResolver$$anon$1.catchNonFatal(CoursierResolver.scala:35)
        at com.github.johnynek.bazel_deps.MakeDeps$$anonfun$resolve$1.apply(MakeDeps.scala:126)
        at com.github.johnynek.bazel_deps.MakeDeps$$anonfun$resolve$1.apply(MakeDeps.scala:124)
        at coursier.util.Task$$anonfun$flatMap$extension$1$$anonfun$apply$1.apply(Task.scala:10)
        at coursier.util.Task$$anonfun$flatMap$extension$1$$anonfun$apply$1.apply(Task.scala:10)
        at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:253)
        at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251)
        at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:36)
        at scala.concurrent.impl.ExecutionContextImpl$AdaptedForkJoinTask.exec(ExecutionContextImpl.scala:121)
        at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.pollAndExecAll(ForkJoinPool.java:1253)
        at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1346)
        at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
        at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)

In particular, the error message doesn't mention the resolver at all.

cc @gdeest

johnynek commented 5 years ago

https://github.com/johnynek/bazel-deps/blob/8cb3711e675a5bd0109bfcb4a0bd50143b640a78/src/scala/com/github/johnynek/bazel_deps/MakeDeps.scala#L127

Here is the line.

That happens when we fail to resolve a declared jar. That shouldn’t be where we get the error but a better message could be added there: filter all the nodes we can’t find, print all of them and suggest to check the resolver.

A better fix would be to actually have Coursier error. Maybe this is a bug report for Coursier.