mirror of
				https://github.com/redis/go-redis.git
				synced 2025-11-04 02:33:24 +03:00 
			
		
		
		
	fix(panic): Return error instead of panic from commands (#3568)
Instead of panic in few commands, we can return an error to avoid unexpected panics in application code.
This commit is contained in:
		@@ -2,6 +2,7 @@ package redis
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"context"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
@@ -313,7 +314,9 @@ func (c cmdable) ZPopMax(ctx context.Context, key string, count ...int64) *ZSlic
 | 
			
		||||
	case 1:
 | 
			
		||||
		args = append(args, count[0])
 | 
			
		||||
	default:
 | 
			
		||||
		panic("too many arguments")
 | 
			
		||||
		cmd := NewZSliceCmd(ctx)
 | 
			
		||||
		cmd.SetErr(errors.New("too many arguments"))
 | 
			
		||||
		return cmd
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cmd := NewZSliceCmd(ctx, args...)
 | 
			
		||||
@@ -333,7 +336,9 @@ func (c cmdable) ZPopMin(ctx context.Context, key string, count ...int64) *ZSlic
 | 
			
		||||
	case 1:
 | 
			
		||||
		args = append(args, count[0])
 | 
			
		||||
	default:
 | 
			
		||||
		panic("too many arguments")
 | 
			
		||||
		cmd := NewZSliceCmd(ctx)
 | 
			
		||||
		cmd.SetErr(errors.New("too many arguments"))
 | 
			
		||||
		return cmd
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cmd := NewZSliceCmd(ctx, args...)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user