From 198e7e831e06f8cef17f61c9f2f90f736cfee7c1 Mon Sep 17 00:00:00 2001 From: "bazel.build machine account" <15028808+bazel-io@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:16:36 +0100 Subject: [PATCH] [7.1.0] Fix crash on `bazel mod` error containing `%` (#20651) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `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. Commit https://github.com/bazelbuild/bazel/commit/6e6e6f8442533647fca308b7d7fb36f75b2485b1 PiperOrigin-RevId: 592942775 Change-Id: Ida5c234413c1647f81d3702bb9deeedcdd93df12 Co-authored-by: Fabian Meumertzheim Co-authored-by: Xùdōng Yáng Co-authored-by: Ian (Hee) Cha --- .../devtools/build/lib/bazel/commands/ModCommand.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/commands/ModCommand.java b/src/main/java/com/google/devtools/build/lib/bazel/commands/ModCommand.java index 92267202f7be96..77c0be124615c8 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/commands/ModCommand.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/commands/ModCommand.java @@ -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); } @@ -494,13 +494,10 @@ private static ImmutableSortedSet 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); }