From 50ac4c55e4cc53619691c7c7c9272c4c96f134c0 Mon Sep 17 00:00:00 2001 From: Xiaolong Chen Date: Sun, 21 Dec 2025 16:03:23 +0800 Subject: [PATCH 1/2] Use errors.Join() instead of custom error join func Signed-off-by: Xiaolong Chen --- export_test.go | 4 -- sentinel.go | 18 +-------- sentinel_test.go | 96 ------------------------------------------------ 3 files changed, 1 insertion(+), 117 deletions(-) diff --git a/export_test.go b/export_test.go index 97b6179a44..c1b77683f3 100644 --- a/export_test.go +++ b/export_test.go @@ -106,7 +106,3 @@ func (c *ModuleLoadexConfig) ToArgs() []interface{} { func ShouldRetry(err error, retryTimeout bool) bool { return shouldRetry(err, retryTimeout) } - -func JoinErrors(errs []error) string { - return joinErrors(errs) -} diff --git a/sentinel.go b/sentinel.go index 663f7b1ad9..73428b9828 100644 --- a/sentinel.go +++ b/sentinel.go @@ -16,7 +16,6 @@ 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" "github.com/redis/go-redis/v9/maintnotifications" "github.com/redis/go-redis/v9/push" ) @@ -904,22 +903,7 @@ 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: %s", joinErrors(errs)) -} - -func joinErrors(errs []error) string { - if len(errs) == 0 { - return "" - } - 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) + return "", fmt.Errorf("redis: all sentinels specified in configuration are unreachable: %w", errors.Join(errs...)) } func (c *sentinelFailover) replicaAddrs(ctx context.Context, useDisconnected bool) ([]string, error) { diff --git a/sentinel_test.go b/sentinel_test.go index 0f0f61ebf7..f332822f5b 100644 --- a/sentinel_test.go +++ b/sentinel_test.go @@ -682,99 +682,3 @@ func compareSlices(t *testing.T, a, b []string, name string) { } } } - -type joinErrorsTest struct { - name string - errs []error - expected string -} - -func TestJoinErrors(t *testing.T) { - tests := []joinErrorsTest{ - { - name: "empty slice", - errs: []error{}, - expected: "", - }, - { - name: "single error", - errs: []error{errors.New("first error")}, - expected: "first error", - }, - { - name: "two errors", - errs: []error{errors.New("first error"), errors.New("second error")}, - expected: "first error\nsecond error", - }, - { - name: "multiple errors", - errs: []error{ - errors.New("first error"), - errors.New("second error"), - errors.New("third error"), - }, - expected: "first error\nsecond error\nthird error", - }, - { - name: "nil slice", - errs: nil, - expected: "", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - result := redis.JoinErrors(tt.errs) - if result != tt.expected { - t.Errorf("joinErrors() = %q, want %q", result, tt.expected) - } - }) - } -} - -func BenchmarkJoinErrors(b *testing.B) { - benchmarks := []joinErrorsTest{ - { - name: "empty slice", - errs: []error{}, - expected: "", - }, - { - name: "single error", - errs: []error{errors.New("first error")}, - expected: "first error", - }, - { - name: "two errors", - errs: []error{errors.New("first error"), errors.New("second error")}, - expected: "first error\nsecond error", - }, - { - name: "multiple errors", - errs: []error{ - errors.New("first error"), - errors.New("second error"), - errors.New("third error"), - }, - expected: "first error\nsecond error\nthird error", - }, - { - name: "nil slice", - errs: nil, - expected: "", - }, - } - for _, bm := range benchmarks { - b.Run(bm.name, func(b *testing.B) { - b.ResetTimer() - b.RunParallel(func(pb *testing.PB) { - for pb.Next() { - result := redis.JoinErrors(bm.errs) - if result != bm.expected { - b.Errorf("joinErrors() = %q, want %q", result, bm.expected) - } - } - }) - }) - } -} From f0ae0809e6053407a17b284de62fe88dec852555 Mon Sep 17 00:00:00 2001 From: Xiaolong Chen Date: Sun, 21 Dec 2025 22:38:04 +0800 Subject: [PATCH 2/2] CI Signed-off-by: Xiaolong Chen