This is an automated email from the ASF dual-hosted git repository.

jsancio pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 82de719fff5 MINOR; Improve error message for the storage format 
command (#19210)
82de719fff5 is described below

commit 82de719fff5b0abe827e2f162da0368ea1155623
Author: José Armando García Sancio <[email protected]>
AuthorDate: Sun Mar 23 19:30:57 2025 -0400

    MINOR; Improve error message for the storage format command (#19210)
    
    Minor improvement on the error output for the storage format command. 
Suggests changes for a valid storage format command.
    
    Reviewers: Justine Olshan <[email protected]>
---
 .../apache/kafka/metadata/storage/Formatter.java   | 19 ++++++----
 .../kafka/metadata/storage/FormatterTest.java      | 40 +++++++++++++---------
 2 files changed, 37 insertions(+), 22 deletions(-)

diff --git 
a/metadata/src/main/java/org/apache/kafka/metadata/storage/Formatter.java 
b/metadata/src/main/java/org/apache/kafka/metadata/storage/Formatter.java
index 878c0ce042d..04b52c9e665 100644
--- a/metadata/src/main/java/org/apache/kafka/metadata/storage/Formatter.java
+++ b/metadata/src/main/java/org/apache/kafka/metadata/storage/Formatter.java
@@ -347,15 +347,22 @@ public class Formatter {
         if (configuredKRaftVersionLevel.isPresent()) {
             if (configuredKRaftVersionLevel.get() == 0) {
                 if (hasDynamicQuorum()) {
-                    throw new FormatterException("Cannot set kraft.version to 
" +
-                        configuredKRaftVersionLevel.get() + " if KIP-853 
configuration is present. " +
-                            "Try removing the --feature flag for 
kraft.version.");
+                    throw new FormatterException(
+                        "Cannot set kraft.version to " +
+                        configuredKRaftVersionLevel.get() +
+                        " if one of the flags --standalone, 
--initial-controllers, or --no-initial-controllers is used. " +
+                        "For dynamic controllers support, try removing the 
--feature flag for kraft.version."
+                    );
                 }
             } else {
                 if (!hasDynamicQuorum()) {
-                    throw new FormatterException("Cannot set kraft.version to 
" +
-                        configuredKRaftVersionLevel.get() + " unless KIP-853 
configuration is present. " +
-                            "Try removing the --feature flag for 
kraft.version.");
+                    throw new FormatterException(
+                        "Cannot set kraft.version to " +
+                        configuredKRaftVersionLevel.get() +
+                        " unless one of the flags --standalone, 
--initial-controllers, or --no-initial-controllers is used. " +
+                        "For dynamic controllers support, try using one of 
--standalone, --initial-controllers, or " +
+                        "--no-initial-controllers."
+                    );
                 }
             }
             return configuredKRaftVersionLevel.get();
diff --git 
a/metadata/src/test/java/org/apache/kafka/metadata/storage/FormatterTest.java 
b/metadata/src/test/java/org/apache/kafka/metadata/storage/FormatterTest.java
index 12161968b1f..6510e15e44d 100644
--- 
a/metadata/src/test/java/org/apache/kafka/metadata/storage/FormatterTest.java
+++ 
b/metadata/src/test/java/org/apache/kafka/metadata/storage/FormatterTest.java
@@ -419,10 +419,12 @@ public class FormatterTest {
             formatter1.formatter.setInitialControllers(DynamicVoters.
                     parse("1@localhost:8020:4znU-ou9Taa06bmEJxsjnw"));
             assertTrue(formatter1.formatter.hasDynamicQuorum());
-            assertEquals("Cannot set kraft.version to 0 if KIP-853 
configuration is present. " +
-                "Try removing the --feature flag for kraft.version.",
-                    assertThrows(FormatterException.class,
-                        () -> formatter1.formatter.run()).getMessage());
+            assertEquals(
+                "Cannot set kraft.version to 0 if one of the flags 
--standalone, --initial-controllers, or " +
+                "--no-initial-controllers is used. For dynamic controllers 
support, try removing the " +
+                "--feature flag for kraft.version.",
+                assertThrows(FormatterException.class, () -> 
formatter1.formatter.run()).getMessage()
+            );
         }
     }
 
@@ -433,10 +435,12 @@ public class FormatterTest {
             formatter1.formatter.setFeatureLevel("kraft.version", (short) 1);
             formatter1.formatter.setUnstableFeatureVersionsEnabled(true);
             assertFalse(formatter1.formatter.hasDynamicQuorum());
-            assertEquals("Cannot set kraft.version to 1 unless KIP-853 
configuration is present. " +
-                "Try removing the --feature flag for kraft.version.",
-                    assertThrows(FormatterException.class,
-                        () -> formatter1.formatter.run()).getMessage());
+            assertEquals(
+                "Cannot set kraft.version to 1 unless one of the flags 
--standalone, --initial-controllers, or " +
+                "--no-initial-controllers is used. For dynamic controllers 
support, try using one of " +
+                "--standalone, --initial-controllers, or 
--no-initial-controllers.",
+                assertThrows(FormatterException.class, () -> 
formatter1.formatter.run()).getMessage()
+            );
         }
     }
 
@@ -526,10 +530,12 @@ public class FormatterTest {
             formatter1.formatter.setUnstableFeatureVersionsEnabled(true);
             formatter1.formatter.setNoInitialControllersFlag(false);
             assertFalse(formatter1.formatter.hasDynamicQuorum());
-            assertEquals("Cannot set kraft.version to 1 unless KIP-853 
configuration is present. " +
-                    "Try removing the --feature flag for kraft.version.",
-                assertThrows(FormatterException.class,
-                    formatter1.formatter::run).getMessage());
+            assertEquals(
+                "Cannot set kraft.version to 1 unless one of the flags 
--standalone, --initial-controllers, or " +
+                "--no-initial-controllers is used. For dynamic controllers 
support, try using one of " +
+                "--standalone, --initial-controllers, or 
--no-initial-controllers.",
+                assertThrows(FormatterException.class, 
formatter1.formatter::run).getMessage()
+            );
         }
     }
 
@@ -541,10 +547,12 @@ public class FormatterTest {
             formatter1.formatter.setUnstableFeatureVersionsEnabled(true);
             formatter1.formatter.setNoInitialControllersFlag(true);
             assertTrue(formatter1.formatter.hasDynamicQuorum());
-            assertEquals("Cannot set kraft.version to 0 if KIP-853 
configuration is present. " +
-                    "Try removing the --feature flag for kraft.version.",
-                assertThrows(FormatterException.class,
-                    formatter1.formatter::run).getMessage());
+            assertEquals(
+                "Cannot set kraft.version to 0 if one of the flags 
--standalone, --initial-controllers, or " +
+                "--no-initial-controllers is used. For dynamic controllers 
support, try removing the " +
+                "--feature flag for kraft.version.",
+                assertThrows(FormatterException.class, 
formatter1.formatter::run).getMessage()
+            );
         }
     }
 }

Reply via email to