Skip to content

Commit

Permalink
Fix NPE in mod show_repo
Browse files Browse the repository at this point in the history
Fixes #22587

Closes #23125.

PiperOrigin-RevId: 657871750
Change-Id: Iab295f330d0b9fcc30207d04a57ad87dacf480b5
  • Loading branch information
laurentlb authored and bazel-io committed Sep 25, 2024
1 parent e43c933 commit dd0e7b8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ private Optional<RepoSpec> checkRepoFromBazelModules(
if (moduleKey == null) {
return Optional.empty();
}
return Optional.of(bazelDepGraphValue.getDepGraph().get(moduleKey).getRepoSpec());
return Optional.ofNullable(bazelDepGraphValue.getDepGraph().get(moduleKey).getRepoSpec());
}

@Nullable
Expand Down
5 changes: 3 additions & 2 deletions src/test/py/bazel/bzlmod/mod_command_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,14 +507,15 @@ def testShowRepoThrowsUnusedModule(self):
stderr,
)

# fix for https://github.com/bazelbuild/bazel/issues/22587
def testShowRepoThrowsNonexistentRepo(self):
_, _, stderr = self.RunBazel(
['mod', 'show_repo', '@@lol'],
['mod', 'show_repo', '<root>'],
allow_failure=True,
rstrip=True,
)
self.assertIn(
"ERROR: In repo argument @@lol: no such repo. Type 'bazel help mod' "
"ERROR: In repo argument <root>: no such repo. Type 'bazel help mod' "
'for syntax and help.',
stderr,
)
Expand Down

0 comments on commit dd0e7b8

Please sign in to comment.