Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhelpful error message for missing BUILD file: looks like referenced file is missing instead #7854

Closed
alexeagle opened this issue Mar 27, 2019 · 1 comment
Assignees
Labels
bad error messaging Issues where users get stuck because they don't understand what they did wrong

Comments

@alexeagle
Copy link
Contributor

User of rules_nodejs hits a problem in bazel-contrib/rules_nodejs#628

In a repository rule, they reference //:yarn.lock

load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")
yarn_install(
    name = "npm",
    package_json = "//:package.json",
    yarn_lock = "//:yarn.lock",
)

But there is no BUILD file in the root of the WORKSPACE.

The error ought to say sth like "you referenced a file in /path/to/workspace but there is no BUILD.bazel file there. Fix by creating an empty file there".

Instead the error is

ERROR: error loading package '': Encountered error while reading extension file 'install_bazel_dependencies.bzl': no such package '@npm//': Traceback (most recent call last):
          File "/private/var/tmp/_bazel_justinmah/684a432d68d5cb4f45acf4255d4873d0/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 237
                          repository_ctx.template("yarn.lock", repository_ctx.path(r...), {})
                                  File "/private/var/tmp/_bazel_justinmah/684a432d68d5cb4f45acf4255d4873d0/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 239, in repository_ctx.template
                                                  repository_ctx.path(repository_ctx.attr.yarn_lock)
  Unable to load package for //:yarn.lock: not found.

The last line is very misleading because it seems like "I couldn't load package" (users may not know what Bazel means by a "package") and the reason is that the yarn.lock file is not found. The user sees that the yarn.lock file is there, so can't understand how to fix this.

@alexeagle alexeagle added the bad error messaging Issues where users get stuck because they don't understand what they did wrong label Mar 27, 2019
@aehlig aehlig self-assigned this Apr 29, 2019
@aehlig
Copy link
Contributor

aehlig commented Apr 29, 2019

I believe this is fixed by now. With bazel at head, the error message currently reads as follows.

aehlig@aehlig1:/tmp/issue-7854$ cat WORKSPACE 
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "build_bazel_rules_nodejs",
    sha256 = "4c702ffeeab2d24dd4101601b6d27cf582d2e0d4cdc3abefddd4834664669b6b",
    urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.28.0/rules_nodejs-0.28.0.tar.gz"],
)

load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")
yarn_install(
    name = "npm",
    package_json = "//:package.json",
    yarn_lock = "//:yarn.lock",
)

load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
install_bazel_dependencies()
aehlig@aehlig1:/tmp/issue-7854$ ls -al
total 300
drwxr-xr-x  2 aehlig primarygroup   4096 Apr 29 11:35 .
drwxrwxrwt 52 root   root         294912 Apr 29 11:36 ..
-rw-r--r--  1 aehlig primarygroup    588 Apr 29 11:35 WORKSPACE
aehlig@aehlig1:/tmp/issue-7854$ bazel build ...
Starting local Bazel server and connecting to it...
(11:36:58) INFO: Invocation ID: 084d748e-6771-4d83-b39e-d9632b684245
(11:36:58) INFO: Current date is 2019-04-29
(11:37:03) INFO: Call stack for the definition of repository 'npm' which is a yarn_install (rule definition at /usr/local/google/home/aehlig/.cache/bazel/_bazel_aehlig/f75f4eb183e8028dc1c9c396d5868f94/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl:298:16):
 - /usr/local/google/home/aehlig/.cache/bazel/_bazel_aehlig/f75f4eb183e8028dc1c9c396d5868f94/external/build_bazel_rules_nodejs/defs.bzl:82:5
 - /tmp/issue-7854/WORKSPACE:9:1
(11:37:03) ERROR: An error occurred during the fetch of repository 'npm':
   Traceback (most recent call last):
	File "/usr/local/google/home/aehlig/.cache/bazel/_bazel_aehlig/f75f4eb183e8028dc1c9c396d5868f94/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 243
		repository_ctx.template("yarn.lock", repository_ctx.path(r...), {})
	File "/usr/local/google/home/aehlig/.cache/bazel/_bazel_aehlig/f75f4eb183e8028dc1c9c396d5868f94/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 245, in repository_ctx.template
		repository_ctx.path(repository_ctx.attr.yarn_lock)
Unable to load package for //:yarn.lock: BUILD file not found in any of the following directories.
 - /tmp/issue-7854
(11:37:03) ERROR: error loading package '': Encountered error while reading extension file 'install_bazel_dependencies.bzl': no such package '@npm//': Traceback (most recent call last):
	File "/usr/local/google/home/aehlig/.cache/bazel/_bazel_aehlig/f75f4eb183e8028dc1c9c396d5868f94/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 243
		repository_ctx.template("yarn.lock", repository_ctx.path(r...), {})
	File "/usr/local/google/home/aehlig/.cache/bazel/_bazel_aehlig/f75f4eb183e8028dc1c9c396d5868f94/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 245, in repository_ctx.template
		repository_ctx.path(repository_ctx.attr.yarn_lock)
Unable to load package for //:yarn.lock: BUILD file not found in any of the following directories.
 - /tmp/issue-7854
(11:37:03) ERROR: error loading package '': Encountered error while reading extension file 'install_bazel_dependencies.bzl': no such package '@npm//': Traceback (most recent call last):
	File "/usr/local/google/home/aehlig/.cache/bazel/_bazel_aehlig/f75f4eb183e8028dc1c9c396d5868f94/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 243
		repository_ctx.template("yarn.lock", repository_ctx.path(r...), {})
	File "/usr/local/google/home/aehlig/.cache/bazel/_bazel_aehlig/f75f4eb183e8028dc1c9c396d5868f94/external/build_bazel_rules_nodejs/internal/npm_install/npm_install.bzl", line 245, in repository_ctx.template
		repository_ctx.path(repository_ctx.attr.yarn_lock)
Unable to load package for //:yarn.lock: BUILD file not found in any of the following directories.
 - /tmp/issue-7854
(11:37:03) INFO: Elapsed time: 5.842s
(11:37:03) INFO: 0 processes.
(11:37:03) FAILED: Build did NOT complete successfully (0 packages loaded)
aehlig@aehlig1:/tmp/issue-7854$ 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bad error messaging Issues where users get stuck because they don't understand what they did wrong
Projects
None yet
Development

No branches or pull requests

2 participants