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

[6.4.0] bazel_dep allows missing version with poor error #19196

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,15 @@ private GetModuleFileResult getModuleFile(
}

// Otherwise, we should get the module file from a registry.
if (key.getVersion().isEmpty()) {
// Print a friendlier error message if the user forgets to specify a version *and* doesn't
// have a non-registry override.
throw errorf(
Code.MODULE_NOT_FOUND,
"bad bazel_dep on module '%s' with no version. Did you forget to specify a version, or a"
+ " non-registry override?",
key.getName());
}
// TODO(wyv): Move registry object creation to BazelRepositoryModule so we don't repeatedly
// create them, and we can better report the error (is it a flag error or override error?).
List<String> registries = Objects.requireNonNull(REGISTRIES.get(env));
Expand All @@ -361,6 +370,7 @@ private GetModuleFileResult getModuleFile(
}
} else if (override != null) {
// This should never happen.
// TODO(wyv): make ModuleOverride a sealed interface so this is checked at compile time.
throw new IllegalStateException(
String.format(
"unrecognized override type %s for module %s",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,19 @@ public void testRootModule_badSelfOverride() throws Exception {
assertThat(result.getError().toString()).contains("invalid override for the root module");
}

@Test
public void forgotVersion() throws Exception {
FakeRegistry registry = registryFactory.newFakeRegistry("/foo");
ModuleFileFunction.REGISTRIES.set(differencer, ImmutableList.of(registry.getUrl()));

SkyKey skyKey = ModuleFileValue.key(createModuleKey("bbb", ""), null);
EvaluationResult<ModuleFileValue> result =
evaluator.evaluate(ImmutableList.of(skyKey), evaluationContext);
assertThat(result.hasError()).isTrue();
assertThat(result.getError().toString())
.contains("bad bazel_dep on module 'bbb' with no version");
}

@Test
public void testRegistriesCascade() throws Exception {
// Registry1 has no module B@1.0; registry2 and registry3 both have it. We should be using the
Expand Down