Geetika,
Yes, more info would be helpful. I have some comments below.
On 7/27/2016 7:37 AM, Geetika Kapoor wrote:
Hi,
I tried to fix NumberFormatException when i did tps-cert-find with
non-integer/invalid range value for size and start.I was doing testing
for tps-cert and then i came across this.I thought giving some
additional info to users inplace of numberformat.I have done similar
fix on rhel7 compile it and make a jar and test on rhel7 .I can share
that patch if needed. Below are the test result.
Before fix testing:
1. pki -h
pki1.example.com -p 25080 tps-cert-find --start "gy"
NumberFormatException: For input string: "gy"
2. pki -h
pki1.example.com -p 25080 tps-cert-find --size "gy"
NumberFormatException: For input string: "gy"
3. pki -p 25080 tps-cert-find --start
1789999999999999999999999999999999999999999999
NumberFormatException: For input string:
"1789999999999999999999999999999999999999999999"
After fix testing:
1. [root@pki1 ~]# pki -d /opt/rhqa_pki/certdb -c Secret123 -h
pki1.example.com -p 25080 tps-cert-find --start "gy"
Error: Enter valid integer value for size/start option
usage: tps-cert-find [FILTER] [OPTIONS...]
--help Show help options
--size <size> Page size
--start <start> Page start
--token <ID> Token ID
I think it would be useful to show the user which the parameter has the
invalid value and also the invalid value itself, so something like this:
Error: Invalid value for --start parameter: gy
2. [root@pki1 ~]# pki -d /opt/rhqa_pki/certdb -c Secret123 -h
pki1.example.com -p 25080 tps-cert-find --size "hy"
Error: Enter valid integer value for size/start option
usage: tps-cert-find [FILTER] [OPTIONS...]
--help Show help options
--size <size> Page size
--start <start> Page start
--token <ID> Token ID
Same thing here:
Error: Invalid value for --size parameter: hy
So you may need to create separate try-catch blocks for each parameter.
Another thing, I'm not sure if we should display the command usage after
the failure. The usage could be very long and it may obscure the error
message. The error message itself should be sufficient to fix the
problem, and if needed the user can see the usage using --help
parameter. We probably can display something like this after the error
message (replace <command> with the actual command name):
Try 'pki <command> --help' for more information.
One more thing, please preserve the formatting of the existing code. We
use 4 spaces instead of tabs for indentation. Thanks.
--
Endi S. Dewata