szetszwo commented on code in PR #1610:
URL: https://github.com/apache/ratis/pull/1610#discussion_r4099962315
##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/peer/SetPriorityCommand.java:
##########
@@ -52,14 +54,13 @@ public String getCommandName() {
@Override
public int run(CommandLine cl) throws IOException {
super.run(cl);
- Map<String, Integer> addressPriorityMap = new HashMap<>();
- for (String optionValue :
cl.getOptionValues(PEER_WITH_NEW_PRIORITY_OPTION_NAME)) {
- String[] str = optionValue.split("[|]");
- if (str.length < 2) {
- println("The format of the parameter is wrong");
- return -1;
- }
- addressPriorityMap.put(str[0], Integer.parseInt(str[1]));
+ final Map<String, Integer> addressPriorityMap;
+ try {
+ addressPriorityMap = parseAddressPriorityMap(
+ cl.getOptionValues(PEER_WITH_NEW_PRIORITY_OPTION_NAME));
+ } catch (IllegalArgumentException e) {
+ println("The format of the parameter is wrong");
Review Comment:
Let's print out the exception:
```java
e.printStackTrace(getPrintStream());
```
##########
ratis-shell/src/main/java/org/apache/ratis/shell/cli/sh/peer/SetPriorityCommand.java:
##########
@@ -107,4 +108,20 @@ public Options getOptions() {
public static String description() {
return "Set priority to ratis peers";
}
+
+ static Map<String, Integer> parseAddressPriorityMap(String[] optionValues) {
+ Map<String, Integer> addressPriorityMap = new HashMap<>();
+ if (optionValues == null) {
+ return addressPriorityMap;
+ }
+ for (String optionValue : optionValues) {
+ String[] str = optionValue.split("[|]");
+ if (str.length < 2) {
+ throw new IllegalArgumentException("The format of the parameter is
wrong");
Review Comment:
Let's add the format and the actual value in the message:
```java
throw new IllegalArgumentException("Invalid option
<PEER_HOST:PEER_PORT|PRIORITY>: " + optionValue);
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]