Skip to content

Commit

Permalink
Fix crash on bazel mod error containing %
Browse files Browse the repository at this point in the history
`bazel mod show_extension @foo//:extensions.bzl%go_sdk`resulted in the crash:
```
java.util.IllegalFormatConversionException: g != java.lang.String
```

Also makes an error more readable by swapping a `:`.

Closes #20627.

PiperOrigin-RevId: 592942775
Change-Id: Ida5c234413c1647f81d3702bb9deeedcdd93df12
  • Loading branch information
fmeum authored and copybara-github committed Dec 21, 2023
1 parent 7a02916 commit 6e6e6f8
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ private BlazeCommandResult execInternal(CommandEnvironment env, OptionsParsingRe
baseModule.getUnusedDeps()));
} catch (InvalidArgumentException | OptionsParsingException e) {
throw new InvalidArgumentException(
String.format("In extension argument: %s %s", arg, e.getMessage()),
String.format("In extension argument %s: %s", arg, e.getMessage()),
Code.INVALID_ARGUMENTS,
e);
}
Expand Down Expand Up @@ -494,13 +494,10 @@ private static ImmutableSortedSet<ModuleExtensionId> extensionArgListToIds(

private static BlazeCommandResult reportAndCreateFailureResult(
CommandEnvironment env, String message, Code detailedCode) {
if (message.charAt(message.length() - 1) != '.') {
message = message.concat(".");
}
String fullMessage =
String.format(
message.concat(" Type '%s help mod' for syntax and help."),
env.getRuntime().getProductName());
"%s%s Type '%s help mod' for syntax and help.",
message, message.endsWith(".") ? "" : ".", env.getRuntime().getProductName());
env.getReporter().handle(Event.error(fullMessage));
return createFailureResult(fullMessage, detailedCode);
}
Expand Down

0 comments on commit 6e6e6f8

Please sign in to comment.