You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/10/28 06:27:55 UTC

[GitHub] [pulsar] yuruguo commented on a change in pull request #12462: [pulsar-admin] Check validity of --types for topic and namespace

yuruguo commented on a change in pull request #12462:
URL: https://github.com/apache/pulsar/pull/12462#discussion_r738056662



##########
File path: pulsar-client-tools/src/main/java/org/apache/pulsar/admin/cli/CmdTopics.java
##########
@@ -1850,15 +1850,24 @@ void run() throws PulsarAdminException {
         @Parameter(description = "persistent://tenant/namespace/topic", required = true)
         private java.util.List<String> params;
 
-        @Parameter(names = { "--types",
-                "-t" }, description = "Subscription types enabled list (comma separated values)", required = true)
-        private String subTypes;
+        @Parameter(names = {"--types", "-t"}, description = "Subscription types enabled list (comma separated values)."
+                + " Possible values: (Exclusive, Shared, Failover, Key_Shared).", required = true)
+        private List<String> subTypes;
 
         @Override
         void run() throws PulsarAdminException {
             String persistentTopic = validatePersistentTopic(params);
             Set<SubscriptionType> types = new HashSet<>();
-            Lists.newArrayList(subTypes.split(",")).forEach(s -> types.add(SubscriptionType.valueOf(s)));
+            subTypes.forEach(s -> {
+                SubscriptionType subType;
+                try {
+                    subType = SubscriptionType.valueOf(s);
+                } catch (IllegalArgumentException exception) {
+                    throw new ParameterException(String.format("Illegal subscription type %s. Possible values: %s.", s,

Review comment:
       Throwing an `ParameterException` does not directly display the exception stack to the CLI, but displays the information in the `ParameterException`, which is the benefit of using `ParameterException`.
   As follows:
   ```
   ./bin/pulsar-admin topics set-subscription-types-enabled --types Share tenant/ns/tp
   Illegal subscription type Share. Possible values: [Exclusive, Shared, Failover, Key_Shared].
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org