This is an automated email from the ASF dual-hosted git repository.
chia7712 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 b4fc7aefcbe MINOR: Improve error handling for StorageTool (#20696)
b4fc7aefcbe is described below
commit b4fc7aefcbe2c68856dfd4b09ee51c5992774a26
Author: jimmy <[email protected]>
AuthorDate: Tue Oct 14 02:41:11 2025 +0800
MINOR: Improve error handling for StorageTool (#20696)
This PR improves error handling for feature argument parsing in the
`StorageTool`. The main change is stricter validation of the expected
format for feature arguments, ensuring users provide them in the correct
`feature=version` format.
**Before:**
* If user using argument like: `./bin/kafka-storage.sh
feature-dependencies --feature group.version`, the following error will
occur, which is a bit confusing:
<img width="970" height="162" alt="image"
src="https://github.com/user-attachments/assets/aa4341f9-6eb8-488e-b88e-f5244560184b"
/>
**After:**
<img width="812" height="55" alt="image"
src="https://github.com/user-attachments/assets/9aedecdb-e657-4bd3-8b9b-22d6282a1dc1"
/>
Reviewers: Chia-Ping Tsai <[email protected]>
---
core/src/main/scala/kafka/tools/StorageTool.scala | 9 ++++++++-
core/src/test/scala/unit/kafka/tools/StorageToolTest.scala | 10 ++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/core/src/main/scala/kafka/tools/StorageTool.scala
b/core/src/main/scala/kafka/tools/StorageTool.scala
index d8048d4d0aa..dc696296fd4 100644
--- a/core/src/main/scala/kafka/tools/StorageTool.scala
+++ b/core/src/main/scala/kafka/tools/StorageTool.scala
@@ -212,7 +212,14 @@ object StorageTool extends Logging {
// Iterate over each feature specified with --feature
for (featureArg <- featureArgs) {
- val Array(featureName, versionStr) = featureArg.split("=")
+ // Improved error handling for feature argument format
+ val parts = featureArg.split("=", 2)
+ if (parts.length != 2) {
+ throw new TerseFailure(s"Invalid feature format: $featureArg. Expected
format: 'feature=version' (e.g. 'group.version=1')")
+ }
+
+ val featureName = parts(0).trim
+ val versionStr = parts(1).trim
val featureLevel = try {
versionStr.toShort
diff --git a/core/src/test/scala/unit/kafka/tools/StorageToolTest.scala
b/core/src/test/scala/unit/kafka/tools/StorageToolTest.scala
index a36ad51572a..78992f98574 100644
--- a/core/src/test/scala/unit/kafka/tools/StorageToolTest.scala
+++ b/core/src/test/scala/unit/kafka/tools/StorageToolTest.scala
@@ -837,6 +837,16 @@ Found problem:
assertEquals("Invalid version format: invalid for feature
metadata.version", exception.getMessage)
}
+ @Test
+ def testHandleFeatureDependenciesForInvalidFormat(): Unit = {
+ val stream = new ByteArrayOutputStream()
+
+ val exception = assertThrows(classOf[TerseFailure], () => {
+ runFeatureDependenciesCommand(stream, Seq("metadata.version"))
+ })
+ assertEquals("Invalid feature format: metadata.version. Expected format:
'feature=version' (e.g. 'group.version=1')", exception.getMessage)
+ }
+
@Test
def testBootstrapScramRecords(): Unit = {
val availableDirs = Seq(TestUtils.tempDir())