Skip to content

Commit b2ba2c2

Browse files
committed
throw error for non-numeric args
1 parent d5fcf12 commit b2ba2c2

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

cmd/navigate.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package cmd
22

33
import (
4-
"fmt"
4+
"strconv"
55

66
"github.com/github/gh-stack/internal/config"
77
"github.com/github/gh-stack/internal/git"
@@ -16,7 +16,12 @@ func UpCmd(cfg *config.Config) *cobra.Command {
1616
RunE: func(cmd *cobra.Command, args []string) error {
1717
n := 1
1818
if len(args) > 0 {
19-
fmt.Sscanf(args[0], "%d", &n)
19+
var err error
20+
n, err = strconv.Atoi(args[0])
21+
if err != nil {
22+
cfg.Errorf("invalid number %q", args[0])
23+
return ErrInvalidArgs
24+
}
2025
}
2126
return runNavigate(cfg, n)
2227
},
@@ -31,7 +36,12 @@ func DownCmd(cfg *config.Config) *cobra.Command {
3136
RunE: func(cmd *cobra.Command, args []string) error {
3237
n := 1
3338
if len(args) > 0 {
34-
fmt.Sscanf(args[0], "%d", &n)
39+
var err error
40+
n, err = strconv.Atoi(args[0])
41+
if err != nil {
42+
cfg.Errorf("invalid number %q", args[0])
43+
return ErrInvalidArgs
44+
}
3545
}
3646
return runNavigate(cfg, -n)
3747
},

0 commit comments

Comments
 (0)