Bazel: Error message when using repository rule in BUILD file is not helpful

Created on 24 Mar 2020  路  2Comments  路  Source: bazelbuild/bazel

Description of the problem / feature request:

Error message when using a repository rule within a BUILD file is not helpful.

Feature requests: what underlying problem are you trying to solve with this feature?

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.

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

  • Create a fresh empty directory
  • Create en empty WORKSPACE file
  • Create the following 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)

What operating system are you running Bazel on?

Ubuntu 18.04

What's the output of bazel info release?

> bazel info release
Starting local Bazel server and connecting to it...
release 2.1.0

I've installed bazel through APT

Have you found anything relevant by searching the web?

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

P1 team-XProduct bug

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.

All 2 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lisaonduty picture lisaonduty  路  3Comments

sandipmgiri picture sandipmgiri  路  3Comments

ajaysaini-sgvu picture ajaysaini-sgvu  路  3Comments

GaofengCheng picture GaofengCheng  路  3Comments

kastiglione picture kastiglione  路  3Comments