From caf00d542e16d546f88b3512461825dbde7d18b8 Mon Sep 17 00:00:00 2001 From: "Ian (Hee) Cha" Date: Mon, 5 Jun 2023 11:00:38 -0700 Subject: [PATCH] Error if repository name isn't supplied (#18425) Currently, this results in a server crash along the lines of: ``` FATAL: bazel crashed due to an internal error. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node '[/redacted]/[WORKSPACE.bazel], 1' (requested by nodes 'com.google.devtools.build.lib.skyframe.ExternalPackageFunction$$Lambda$231/0x0000000800df7998@34f133c') at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:642) at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:382) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: net.starlark.java.eval.Starlark$UncheckedEvalException: NullPointerException thrown during Starlark evaluation (WORKSPACE) at .repository_rule(:0) at .(/redacted/WORKSPACE.bazel:3) Caused by: java.lang.NullPointerException: Cannot invoke "String.isEmpty()" because "name" is null at com.google.devtools.build.lib.cmdline.RepositoryName.create(RepositoryName.java:71) at com.google.devtools.build.lib.packages.WorkspaceFactoryHelper.addMainRepoEntry(WorkspaceFactoryHelper.java:106) at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkRepositoryModule$RepositoryRuleFunction.createRuleLegacy(StarlarkRepositoryModule.java:228) at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkRepositoryModule$RepositoryRuleFunction.call(StarlarkRepositoryModule.java:185) ``` Closes #18335. PiperOrigin-RevId: 530577557 Change-Id: Ic402e8fabac180aaa2da19cd3201b9fb2671dccb Co-authored-by: Daniel Wagner-Hall --- .../bazel/repository/starlark/StarlarkRepositoryModule.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryModule.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryModule.java index e3e58c754fb77c..3dd3e9d8f6d67e 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryModule.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/starlark/StarlarkRepositoryModule.java @@ -225,6 +225,9 @@ private Object createRuleLegacy(StarlarkThread thread, Dict kwar // TODO(adonovan): is this cast safe? Check. String name = (String) kwargs.get("name"); + if (name == null) { + throw Starlark.errorf("argument 'name' is required"); + } WorkspaceFactoryHelper.addMainRepoEntry(packageBuilder, name, thread.getSemantics()); WorkspaceFactoryHelper.addRepoMappings(packageBuilder, kwargs, name); Rule rule =