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

use_repo_rule crashes Bazel when loading a non-existent repo rule #23138

Open
meteorcloudy opened this issue Jul 29, 2024 · 1 comment
Open
Assignees
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug

Comments

@meteorcloudy
Copy link
Member

Description of the bug:

I accidentally load new_git_repository from http.bzl

new_git_repository = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "new_git_repository")

and Bazel crashes like this

Starting local Bazel server and connecting to it...
Computing main repo mapping: 
Computing main repo mapping: 
Computing main repo mapping: 
Loading: 
Loading: 0 packages loaded
Analyzing: target //:foo (1 packages loaded, 0 targets configured)
Analyzing: target //:foo (1 packages loaded, 0 targets configured)
[0 / 1] [Prepa] BazelWorkspaceStatusAction stable-status.txt
FATAL: bazel crashed due to an internal error. Printing stack trace:
java.lang.IllegalStateException: Unexpected analysis error: ConfiguredTargetKey{label=//:foo, config=BuildConfigurationKey[5ce19e8228b5c7a746c76c3e50053c1002c2d8b472fc30897311a7ce4b8fb15c]} -> ErrorInfo{exception=com.google.devtools.build.lib.bazel.bzlmod.ExternalDepsException: @@bazel_tools//tools/build_defs/repo:http.bzl does not export a repository_rule called new_git_repository, yet its use is requested at /usr/local/google/home/pcloudy/.cache/bazel/_bazel_pcloudy/4c5ccabacef1ddac6600d71a1b8bfa58/sandbox/linux-sandbox/2917/execroot/_main/_tmp/f1972a83c536d7254318d49f3ac97cd4/workspace/main/MODULE.bazel:2:19, cycles=[], isCatastrophic=false, isDirectlyTransient=false, isTransitivelyTransient=false}, ([ConfiguredTargetKey{label=//:foo, config=BuildConfigurationKey[5ce19e8228b5c7a746c76c3e50053c1002c2d8b472fc30897311a7ce4b8fb15c]}])
        at com.google.devtools.build.lib.bugreport.BugReport.sendBugReport(BugReport.java:196)
        at com.google.devtools.build.lib.bugreport.BugReport.logUnexpected(BugReport.java:167)
        at com.google.devtools.build.lib.skyframe.SkyframeErrorProcessor.logUnexpectedException(SkyframeErrorProcessor.java:778)
        at com.google.devtools.build.lib.skyframe.SkyframeErrorProcessor.logUnexpectedExceptionOrigin(SkyframeErrorProcessor.java:773)
        at com.google.devtools.build.lib.skyframe.SkyframeErrorProcessor.assertValidAnalysisOrExecutionException(SkyframeErrorProcessor.java:729)
        at com.google.devtools.build.lib.skyframe.SkyframeErrorProcessor.processErrors(SkyframeErrorProcessor.java:282)
        at com.google.devtools.build.lib.skyframe.SkyframeBuildView.analyzeAndExecuteTargets(SkyframeBuildView.java:820)
        at com.google.devtools.build.lib.analysis.BuildView.update(BuildView.java:346)
        at com.google.devtools.build.lib.buildtool.AnalysisAndExecutionPhaseRunner.runAnalysisAndExecutionPhase(AnalysisAndExecutionPhaseRunner.java:227)
        at com.google.devtools.build.lib.buildtool.AnalysisAndExecutionPhaseRunner.execute(AnalysisAndExecutionPhaseRunner.java:125)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargetsWithMergedAnalysisExecution(BuildTool.java:363)
        at com.google.devtools.build.lib.buildtool.BuildTool.buildTargets(BuildTool.java:198)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:548)
        at com.google.devtools.build.lib.buildtool.BuildTool.processRequest(BuildTool.java:516)
        at com.google.devtools.build.lib.runtime.commands.BuildCommand.exec(BuildCommand.java:107)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.execExclusively(BlazeCommandDispatcher.java:679)
        at com.google.devtools.build.lib.runtime.BlazeCommandDispatcher.exec(BlazeCommandDispatcher.java:252)
        at com.google.devtools.build.lib.server.GrpcServerImpl.executeCommand(GrpcServerImpl.java:607)
        at com.google.devtools.build.lib.server.GrpcServerImpl.lambda$run$1(GrpcServerImpl.java:676)
        at io.grpc.Context$1.run(Context.java:566)
        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)

Which category does this issue belong to?

External Dependency

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

No response

Which operating system are you running Bazel on?

No response

What is the output of bazel info release?

No response

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

No response

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

No response

If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

No response

Have you found anything relevant by searching the web?

No response

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

No response

@meteorcloudy meteorcloudy added the team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. label Jul 29, 2024
@fmeum
Copy link
Collaborator

fmeum commented Jul 29, 2024

I think that we should add ExternalDepsException to

if (cause instanceof SaneAnalysisException
|| cause instanceof NoSuchTargetException
|| cause instanceof NoSuchPackageException) {

This isn't needed for repo rule errors as those are translated into a RepositoryFetchException (and thus a NoSuchPackageException) at

new RepositoryFetchException(id, e.getMessage()), Transience.PERSISTENT);

CC @katre

@meteorcloudy meteorcloudy added P2 We'll consider working on this in future. (Assignee optional) and removed untriaged labels Aug 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: bug
Projects
None yet
Development

No branches or pull requests

6 participants
@Wyverald @meteorcloudy @fmeum @iancha1992 @satyanandak and others