Skip to content

Commit 0c717c8

Browse files
authored
Merge pull request #2 from bootjp/feature/fix_error_panic
Refactor error messages for argument length
2 parents 3ffa1a9 + ab678fb commit 0c717c8

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

transport/redis.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,20 +75,21 @@ const (
7575
value = 2
7676
)
7777

78+
var ErrArgsLen = errors.New("ERR wrong number of arguments for command")
79+
7880
func (r *Redis) validateCmd(cmd redcon.Command) error {
7981
if len(cmd.Args) == 0 {
80-
return errors.New("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command")
82+
return ErrArgsLen
8183
}
8284

8385
if len(cmd.Args) < argsLen[string(cmd.Args[commandName])] {
84-
return errors.New("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command")
86+
return ErrArgsLen
8587
}
8688

8789
// check args length
8890
plainCmd := strings.ToUpper(string(cmd.Args[commandName]))
89-
9091
if len(cmd.Args) != argsLen[plainCmd] {
91-
return errors.New("ERR wrong number of arguments for '" + string(cmd.Args[0]) + "' command")
92+
return ErrArgsLen
9293
}
9394

9495
return nil

0 commit comments

Comments
 (0)