Skip to content

Commit 7081036

Browse files
fix: exit with clear error when --waitFor value is not a valid number (#271)
Signed-off-by: puneeth_aditya_5656 <myakampuneeth@gmail.com>
1 parent 2a2f39a commit 7081036

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

cmd/test.go

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command {
7676

7777
// Validate presence and values of flags.
7878
if !strings.HasSuffix(waitFor, "milli") && !strings.HasSuffix(waitFor, "sec") && !strings.HasSuffix(waitFor, "min") {
79-
fmt.Println("--waitFor format is wrong. Applying default 5sec")
79+
fmt.Println("--waitFor format is wrong. Accepted units are: milli, sec, min (e.g. 500milli, 30sec, 5min)")
80+
os.Exit(1)
8081
}
8182

8283
// Collect optional HTTPS transport flags.
@@ -85,15 +86,28 @@ func NewTestCommand(globalClientOpts *connectors.ClientOptions) *cobra.Command {
8586
config.Verbose = globalClientOpts.Verbose
8687

8788
// Compute time to wait in milliseconds.
88-
var waitForMilliseconds int64 = 5000
89+
var waitForMilliseconds int64
8990
if strings.HasSuffix(waitFor, "milli") {
90-
waitForMilliseconds, _ = strconv.ParseInt(waitFor[:len(waitFor)-5], 0, 64)
91+
n, err := strconv.ParseInt(waitFor[:len(waitFor)-5], 0, 64)
92+
if err != nil {
93+
fmt.Printf("--waitFor value %q is not a valid number\n", waitFor)
94+
os.Exit(1)
95+
}
96+
waitForMilliseconds = n
9197
} else if strings.HasSuffix(waitFor, "sec") {
92-
waitForMilliseconds, _ = strconv.ParseInt(waitFor[:len(waitFor)-3], 0, 64)
93-
waitForMilliseconds = waitForMilliseconds * 1000
98+
n, err := strconv.ParseInt(waitFor[:len(waitFor)-3], 0, 64)
99+
if err != nil {
100+
fmt.Printf("--waitFor value %q is not a valid number\n", waitFor)
101+
os.Exit(1)
102+
}
103+
waitForMilliseconds = n * 1000
94104
} else if strings.HasSuffix(waitFor, "min") {
95-
waitForMilliseconds, _ = strconv.ParseInt(waitFor[:len(waitFor)-3], 0, 64)
96-
waitForMilliseconds = waitForMilliseconds * 60 * 1000
105+
n, err := strconv.ParseInt(waitFor[:len(waitFor)-3], 0, 64)
106+
if err != nil {
107+
fmt.Printf("--waitFor value %q is not a valid number\n", waitFor)
108+
os.Exit(1)
109+
}
110+
waitForMilliseconds = n * 60 * 1000
97111
}
98112

99113
var mc connectors.MicrocksClient

0 commit comments

Comments
 (0)