MINOR: Wrapping exceptions in usage for groups and metrics utility (#19151)

If specified an invalid option then an exception trace appears with
`kafka-client-metrics.sh` and `kafka-groups.sh` utilities. Then once has
to explicitly remove the invalid argument and append `--help` to fetch
correct options. The PR fixes below error message to one with `cause`
and `usage`. This behaviour is similar to `kafka-console-consumer.sh`
and `kafka-console-share-consumer.sh`

Reviewers: Andrew Schofield <aschofield@confluent.io>
This commit is contained in:
Apoorv Mittal 2025-03-07 16:30:16 +00:00 committed by GitHub
parent d04cddeb71
commit 8b955b54da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -49,6 +49,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import joptsimple.ArgumentAcceptingOptionSpec;
import joptsimple.OptionException;
import joptsimple.OptionSpec;
import joptsimple.OptionSpecBuilder;
@ -260,7 +261,11 @@ public class ClientMetricsCommand {
.ofType(String.class)
.withValuesSeparatedBy(',');
try {
options = parser.parse(args);
} catch (OptionException oe) {
CommandLineUtils.printUsageAndExit(parser, oe.getMessage());
}
checkArgs();
}

View File

@ -40,6 +40,7 @@ import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;
import joptsimple.ArgumentAcceptingOptionSpec;
import joptsimple.OptionException;
import joptsimple.OptionSpec;
import joptsimple.OptionSpecBuilder;
@ -217,7 +218,11 @@ public class GroupsCommand {
+ "This matches group type 'consumer', and group type 'classic' where the protocol type is 'consumer' or empty.");
shareOpt = parser.accepts("share", "Filter the groups to show share groups.");
try {
options = parser.parse(args);
} catch (OptionException oe) {
CommandLineUtils.printUsageAndExit(parser, oe.getMessage());
}
checkArgs();
}