Skip to content

Commit 972950f

Browse files
committed
don't panic if you don't have to
1 parent af5ff0d commit 972950f

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

redis.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -557,18 +557,16 @@ func (c *baseClient) process(ctx context.Context, cmd Cmder) error {
557557
return lastErr
558558
}
559559

560-
func (c *baseClient) assertUnstableCommand(cmd Cmder) bool {
560+
func (c *baseClient) assertUnstableCommand(cmd Cmder) (bool, error) {
561561
switch cmd.(type) {
562562
case *AggregateCmd, *FTInfoCmd, *FTSpellCheckCmd, *FTSearchCmd, *FTSynDumpCmd:
563563
if c.opt.UnstableResp3 {
564-
return true
564+
return true, nil
565565
} else {
566-
// TODO: find the best way to remove the panic and return error here
567-
// The client should not panic when executing a command, only when initializing.
568-
panic("RESP3 responses for this command are disabled because they may still change. Please set the flag UnstableResp3 . See the [README](https://github.com/redis/go-redis/blob/master/README.md) and the release notes for guidance.")
566+
return false, fmt.Errorf("RESP3 responses for this command are disabled because they may still change. Please set the flag UnstableResp3. See the README and the release notes for guidance")
569567
}
570568
default:
571-
return false
569+
return false, nil
572570
}
573571
}
574572

@@ -594,8 +592,14 @@ func (c *baseClient) _process(ctx context.Context, cmd Cmder, attempt int) (bool
594592
}
595593
readReplyFunc := cmd.readReply
596594
// Apply unstable RESP3 search module.
597-
if c.opt.Protocol != 2 && c.assertUnstableCommand(cmd) {
598-
readReplyFunc = cmd.readRawReply
595+
if c.opt.Protocol != 2 {
596+
useRawReply, err := c.assertUnstableCommand(cmd)
597+
if err != nil {
598+
return err
599+
}
600+
if useRawReply {
601+
readReplyFunc = cmd.readRawReply
602+
}
599603
}
600604
if err := cn.WithReader(c.context(ctx), c.cmdTimeout(cmd), func(rd *proto.Reader) error {
601605
// To be sure there are no buffered push notifications, we process them before reading the reply

0 commit comments

Comments
 (0)