From 736bbd872e6a20cfcc0926b57ea31ccb06f4163f Mon Sep 17 00:00:00 2001 From: Xiaolong Chen Date: Tue, 22 Jul 2025 16:24:56 +0800 Subject: [PATCH] fix: `errors.Join` requires Go 1.20 or later Signed-off-by: Xiaolong Chen --- sentinel.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sentinel.go b/sentinel.go index 04c0f7269..4b4d45077 100644 --- a/sentinel.go +++ b/sentinel.go @@ -16,6 +16,7 @@ import ( "github.com/redis/go-redis/v9/internal" "github.com/redis/go-redis/v9/internal/pool" "github.com/redis/go-redis/v9/internal/rand" + "github.com/redis/go-redis/v9/internal/util" ) //------------------------------------------------------------------------------ @@ -782,7 +783,20 @@ func (c *sentinelFailover) MasterAddr(ctx context.Context) (string, error) { for err := range errCh { errs = append(errs, err) } - return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %w", errors.Join(errs...)) + return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %s", joinErrors(errs)) +} + +func joinErrors(errs []error) string { + if len(errs) == 1 { + return errs[0].Error() + } + + b := []byte(errs[0].Error()) + for _, err := range errs[1:] { + b = append(b, '\n') + b = append(b, err.Error()...) + } + return util.BytesToString(b) } func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected bool) ([]string, error) {