@@ -212,6 +212,25 @@ func NewOOMError(msg string) *OOMError {
212212 return & OOMError {msg : msg }
213213}
214214
215+ // NoReplicasError is returned when not enough replicas acknowledge a write.
216+ // This error occurs when using WAIT/WAITAOF commands or CLUSTER SETSLOT with
217+ // synchronous replication, and the required number of replicas cannot confirm
218+ // the write within the timeout period.
219+ type NoReplicasError struct {
220+ msg string
221+ }
222+
223+ func (e * NoReplicasError ) Error () string {
224+ return e .msg
225+ }
226+
227+ func (e * NoReplicasError ) RedisError () {}
228+
229+ // NewNoReplicasError creates a new NoReplicasError with the given message.
230+ func NewNoReplicasError (msg string ) * NoReplicasError {
231+ return & NoReplicasError {msg : msg }
232+ }
233+
215234// parseTypedRedisError parses a Redis error message and returns a typed error if applicable.
216235// This function maintains backward compatibility by keeping the same error messages.
217236func parseTypedRedisError (msg string ) error {
@@ -235,6 +254,8 @@ func parseTypedRedisError(msg string) error {
235254 return NewTryAgainError (msg )
236255 case strings .HasPrefix (msg , "MASTERDOWN " ):
237256 return NewMasterDownError (msg )
257+ case strings .HasPrefix (msg , "NOREPLICAS " ):
258+ return NewNoReplicasError (msg )
238259 case msg == "ERR max number of clients reached" :
239260 return NewMaxClientsError (msg )
240261 case strings .HasPrefix (msg , "NOAUTH " ), strings .HasPrefix (msg , "WRONGPASS " ), strings .Contains (msg , "unauthenticated" ):
@@ -486,3 +507,21 @@ func IsOOMError(err error) bool {
486507 // Fallback to string checking for backward compatibility
487508 return strings .HasPrefix (err .Error (), "OOM " )
488509}
510+
511+ // IsNoReplicasError checks if an error is a NoReplicasError, even if wrapped.
512+ func IsNoReplicasError (err error ) bool {
513+ if err == nil {
514+ return false
515+ }
516+ var noReplicasErr * NoReplicasError
517+ if errors .As (err , & noReplicasErr ) {
518+ return true
519+ }
520+ // Check if wrapped error is a RedisError with NOREPLICAS prefix
521+ var redisErr RedisError
522+ if errors .As (err , & redisErr ) && strings .HasPrefix (redisErr .Error (), "NOREPLICAS " ) {
523+ return true
524+ }
525+ // Fallback to string checking for backward compatibility
526+ return strings .HasPrefix (err .Error (), "NOREPLICAS " )
527+ }
0 commit comments