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

Repository rule errors are printed three times #18488

Open
layus opened this issue May 24, 2023 · 0 comments
Open

Repository rule errors are printed three times #18488

layus opened this issue May 24, 2023 · 0 comments
Labels
help wanted Someone outside the Bazel team could own this P3 We're not considering working on this, but happy to review a PR. (No assignee) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@layus
Copy link
Contributor

layus commented May 24, 2023

Description of the bug:

When a repository rule implementation wants to report a failure, the only option right now is to use fail(<msg>), but that will print the message three times in the output. Here is an example with a syntax error, but fail() invocations behave the same:

$ bazel build @terse//:'*'
INFO: Repository terse instantiated at:
  /home/layus/projects/bazel-bug/repeated_error/WORKSPACE:3:10: in 
Repository rule repo_fail defined at:
  /home/layus/projects/bazel-bug/repeated_error/main.bzl:23:28: in 
ERROR: An error occurred during the fetch of repository 'terse':
   Traceback (most recent call last):
	File "/home/layus/projects/bazel-bug/repeated_error/main.bzl", line 3, column 29, in _repo_fail
		verbose = repository_ctx.attrs.verbose
Error: 'repository_ctx' value has no field or method 'attrs' (did you mean 'attr'?)
ERROR: /home/layus/projects/bazel-bug/repeated_error/WORKSPACE:3:10: fetching repo_fail rule //external:terse: Traceback (most recent call last):
	File "/home/layus/projects/bazel-bug/repeated_error/main.bzl", line 3, column 29, in _repo_fail
		verbose = repository_ctx.attrs.verbose
Error: 'repository_ctx' value has no field or method 'attrs' (did you mean 'attr'?)
ERROR: 'repository_ctx' value has no field or method 'attrs' (did you mean 'attr'?)
INFO: Elapsed time: 0.073s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded)

The problem is that this error message is the only place to provide information about the failure. We often see messages spanning 10s or 100s of lines there from rules_nixpkgs, as the error contains the output of the underlying command. Printing it three times (four including quiet = False) scrambles the log, and is generally unhelpful.

Not sure about the proper fix, but maybe an 'error()' builtin, related to #4772 ?
Or wrapping https://github.com/bazelbuild/bazel/blob/7.0.0-pre.20230123.5/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryFunction.java#L267-L273 with an AlreadyReportedRepositoryAccessException ?, leaving only the last one to get rid of ?

My impression here is that the two backtraces are about the same, and one should go. As for the last error, it should only contain a single line summary, not the full message again.

See https://gist.github.com/layus/005db27d799612bc7cbc0ccbf4cf554d#file-output-md for more insights

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

See https://gist.github.com/layus/005db27d799612bc7cbc0ccbf4cf554d#file-output-md for a detailed MWE.

Which operating system are you running Bazel on?

Ubuntu

What is the output of bazel info release?

7.0.0-pre.20230123.5

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

built with nix

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

https://gist.github.com/layus/005db27d799612bc7cbc0ccbf4cf554d#file-output-md

Also, a library-side improvement for readability tweag/rules_nixpkgs#389

@Pavank1992 Pavank1992 added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label May 25, 2023
@meteorcloudy meteorcloudy added P3 We're not considering working on this, but happy to review a PR. (No assignee) help wanted Someone outside the Bazel team could own this and removed untriaged labels Jun 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Someone outside the Bazel team could own this P3 We're not considering working on this, but happy to review a PR. (No assignee) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

4 participants