Error message when using a repository rule within a BUILD file is not helpful.
I'd like to make bazel friendlier to newcomers, by having the error message state that a repository rule should not be in a BUILD file, but should be moved into the WORKSPACE file.
BUILD.bazel file:load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
http_file(
name = "bazel_authors",
urls = ["https://github.com/bazelbuild/bazel/blob/master/AUTHORS"],
)
Call bazel build //..., the error message is as follows:
Internal error thrown during build. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node 'PACKAGE:' (requested by nodes 'PACKAGE_ERROR_MESSAGE:')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:515)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:399)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: 'repo_mapping' may only be used in the //external package
at com.google.devtools.build.lib.packages.Package.finishInit(Package.java:410)
at com.google.devtools.build.lib.packages.Package.access$2900(Package.java:80)
at com.google.devtools.build.lib.packages.Package$Builder.finishBuild(Package.java:1543)
at com.google.devtools.build.lib.skyframe.PackageFunction.compute(PackageFunction.java:540)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:438)
... 4 more
INFO: Elapsed time: 0.164s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (1 packages loaded)
Internal error thrown during build. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node 'PACKAGE:' (requested by nodes 'PACKAGE_ERROR_MESSAGE:')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:515)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:399)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: 'repo_mapping' may only be used in the //external package
at com.google.devtools.build.lib.packages.Package.finishInit(Package.java:410)
at com.google.devtools.build.lib.packages.Package.access$2900(Package.java:80)
at com.google.devtools.build.lib.packages.Package$Builder.finishBuild(Package.java:1543)
at com.google.devtools.build.lib.skyframe.PackageFunction.compute(PackageFunction.java:540)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:438)
... 4 more
java.lang.RuntimeException: Unrecoverable error while evaluating node 'PACKAGE:' (requested by nodes 'PACKAGE_ERROR_MESSAGE:')
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:515)
at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:399)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: 'repo_mapping' may only be used in the //external package
at com.google.devtools.build.lib.packages.Package.finishInit(Package.java:410)
at com.google.devtools.build.lib.packages.Package.access$2900(Package.java:80)
at com.google.devtools.build.lib.packages.Package$Builder.finishBuild(Package.java:1543)
at com.google.devtools.build.lib.skyframe.PackageFunction.compute(PackageFunction.java:540)
at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:438)
FAILED: Build did NOT complete successfully (1 packages loaded)
Ubuntu 18.04
bazel info release?> bazel info release
Starting local Bazel server and connecting to it...
release 2.1.0
I've installed bazel through APT
Searching the error message yields hits in bazel's source code! Such as https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/packages/Package.java
I hit this when calling container_pull from rules_docker but I can't find repo_mapping in my repo etc. If I move the call from the BUILD.bazel to the WORKSPACE it works fine but with this message I am not sure why.
Repository rules can only be called during workspace loading. So moving the call out of BUILD.bazel is the right thing to do.
I'm going to fix the error message. The text is wrong (repo_mapping) and the location of the problem is missing.
Also, Bazel should never show Java stacktraces.
Most helpful comment
Repository rules can only be called during workspace loading. So moving the call out of BUILD.bazel is the right thing to do.
I'm going to fix the error message. The text is wrong (repo_mapping) and the location of the problem is missing.
Also, Bazel should never show Java stacktraces.