From d7c6bd3aa2f88ea278b20bd13c4d4fe0fc0f0030 Mon Sep 17 00:00:00 2001 From: Yusuke Kadowaki Date: Wed, 19 Apr 2023 10:35:25 +0900 Subject: [PATCH] Refactor replace errors wrap with join (#2001) * replace for internal pkgs * fix want error message * fix test * fix test for pkg * replace Wrap with Join for pkg packages * fix test to adopt to errors.Join * replace some left errors.Wrap with errors.Join * fix error handling * revert to errors.Wrap to pass the grpc stream test --------- Co-authored-by: Yusuke Kato --- .../benchmark/internal/operation/operation.go | 10 ++- internal/backoff/backoff.go | 4 +- internal/circuitbreaker/manager.go | 4 +- .../client/v1/client/discoverer/discover.go | 12 +-- internal/compress/gzip.go | 4 +- internal/compress/gzip_test.go | 8 +- internal/compress/lz4.go | 4 +- internal/compress/zstd.go | 2 +- internal/compress/zstd_test.go | 2 +- internal/config/config.go | 2 +- internal/db/kvs/redis/redis.go | 2 +- internal/db/kvs/redis/redis_test.go | 4 +- internal/db/nosql/cassandra/option_test.go | 28 ++++-- internal/db/rdb/mysql/mysql.go | 4 +- internal/db/rdb/mysql/mysql_test.go | 4 +- internal/db/storage/blob/s3/option_test.go | 4 +- internal/errgroup/group.go | 2 +- internal/errgroup/group_test.go | 2 +- internal/file/file.go | 32 +++---- internal/log/zap/zap.go | 2 +- internal/net/control/control.go | 26 +++--- internal/net/dialer.go | 4 +- internal/net/grpc/client.go | 8 +- internal/net/grpc/pool/pool.go | 12 +-- internal/net/grpc/stream.go | 7 +- internal/net/http/client/option_test.go | 24 ++++- internal/net/http/middleware/timeout.go | 2 +- internal/net/http/transport/roundtrip.go | 2 +- internal/observability/observability.go | 2 +- internal/safety/safety.go | 2 +- internal/servers/server/server.go | 6 +- internal/timeutil/time.go | 2 +- internal/unit/unit.go | 2 +- internal/unit/unit_test.go | 2 +- internal/worker/worker.go | 2 +- .../core/ngt/handler/grpc/insert_test.go | 90 ++++++++----------- .../core/ngt/handler/grpc/linear_search.go | 4 +- pkg/agent/core/ngt/handler/grpc/search.go | 4 +- pkg/agent/core/ngt/handler/grpc/upsert.go | 4 +- pkg/agent/core/ngt/service/ngt.go | 20 ++--- pkg/agent/core/ngt/service/option_test.go | 14 +-- pkg/agent/internal/metadata/metadata.go | 4 +- pkg/gateway/filter/handler/grpc/handler.go | 52 +++++------ pkg/gateway/filter/usecase/vald.go | 4 +- pkg/manager/index/service/indexer.go | 4 +- pkg/tools/cli/loadtest/service/loader.go | 2 +- pkg/tools/cli/loadtest/usecase/load.go | 4 +- tests/e2e/operation/stream.go | 52 +++++------ 48 files changed, 257 insertions(+), 240 deletions(-) diff --git a/hack/benchmark/internal/operation/operation.go b/hack/benchmark/internal/operation/operation.go index f0f8bfda42..3a77fe3b66 100644 --- a/hack/benchmark/internal/operation/operation.go +++ b/hack/benchmark/internal/operation/operation.go @@ -20,7 +20,8 @@ import ( "github.com/vdaas/vald/apis/grpc/v1/payload" "github.com/vdaas/vald/hack/benchmark/internal/assets" "github.com/vdaas/vald/internal/client/v1/client" - "github.com/vdaas/vald/internal/errors" + "github.com/vdaas/vald/internal/net/grpc/status" + "google.golang.org/grpc/codes" ) type Operation interface { @@ -56,8 +57,11 @@ func (o *operation) CreateIndex(ctx context.Context, b *testing.B) { b.Run("CreateIndex", func(b *testing.B) { for i := 0; i < b.N; i++ { _, err := o.indexerC.CreateIndex(ctx, req) - if err != nil && !errors.Is(err, errors.ErrUncommittedIndexNotFound) { - b.Error(err) + if err != nil { + st, _ := status.FromError(err) + if st.Code() != codes.FailedPrecondition { + b.Error(err) + } } } }) diff --git a/internal/backoff/backoff.go b/internal/backoff/backoff.go index b11c9f2fca..e91cf60631 100644 --- a/internal/backoff/backoff.go +++ b/internal/backoff/backoff.go @@ -130,7 +130,7 @@ func (b *backoff) Do(ctx context.Context, f func(ctx context.Context) (val inter log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) return nil, err default: - return nil, errors.Wrap(err, dctx.Err().Error()) + return nil, errors.Join(err, dctx.Err()) } default: res, ret, err = func() (val interface{}, retryable bool, err error) { @@ -174,7 +174,7 @@ func (b *backoff) Do(ctx context.Context, f func(ctx context.Context) (val inter log.Debugf("[backoff]\tfor: "+name+",\tCanceled\terror: %v", err.Error()) return nil, err default: - return nil, errors.Wrap(dctx.Err(), err.Error()) + return nil, errors.Join(dctx.Err(), err) } case <-timer.C: if dur >= b.durationLimit { diff --git a/internal/circuitbreaker/manager.go b/internal/circuitbreaker/manager.go index 59a8da20fb..a7846b9aaa 100644 --- a/internal/circuitbreaker/manager.go +++ b/internal/circuitbreaker/manager.go @@ -97,11 +97,11 @@ func (bm *breakerManager) Do(ctx context.Context, key string, fn func(ctx contex err = errors.Wrapf(err, "circuitbreaker state is %s, this error is not caused by circuitbreaker", st.String()) case StateOpen: if !errors.Is(err, errors.ErrCircuitBreakerOpenState) { - err = errors.Wrap(err, errors.ErrCircuitBreakerOpenState.Error()) + err = errors.Join(err, errors.ErrCircuitBreakerOpenState) } case StateHalfOpen: if !errors.Is(err, errors.ErrCircuitBreakerHalfOpenFlowLimitation) { - err = errors.Wrap(err, errors.ErrCircuitBreakerHalfOpenFlowLimitation.Error()) + err = errors.Join(err, errors.ErrCircuitBreakerHalfOpenFlowLimitation) } } return val, err diff --git a/internal/client/v1/client/discoverer/discover.go b/internal/client/v1/client/discoverer/discover.go index 51c0b521b8..c553219c93 100644 --- a/internal/client/v1/client/discoverer/discover.go +++ b/internal/client/v1/client/discoverer/discover.go @@ -103,7 +103,7 @@ func (c *client) Start(ctx context.Context) (<-chan error, error) { err = c.discover(ctx, ech) if err != nil { close(ech) - return nil, errors.Wrap(c.dscClient.Close(ctx), err.Error()) + return nil, errors.Join(c.dscClient.Close(ctx), err) } c.eg.Go(safety.RecoverFunc(func() (err error) { @@ -114,17 +114,17 @@ func (c *client) Start(ctx context.Context) (<-chan error, error) { var errs error err = c.dscClient.Close(ctx) if err != nil { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } if c.autoconn && c.client != nil { err = c.client.Close(ctx) if err != nil { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } } err = ctx.Err() if err != nil && err != context.Canceled { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } return errs } @@ -373,7 +373,7 @@ func (c *client) disconnectOldAddrs(ctx context.Context, oldAddrs, connectedAddr if err != nil { select { case <-ctx.Done(): - return errors.Wrap(ctx.Err(), err.Error()) + return errors.Join(ctx.Err(), err) case ech <- err: return err } @@ -383,7 +383,7 @@ func (c *client) disconnectOldAddrs(ctx context.Context, oldAddrs, connectedAddr }); err != nil { select { case <-ctx.Done(): - return errors.Wrap(ctx.Err(), err.Error()) + return errors.Join(ctx.Err(), err) case ech <- err: return err } diff --git a/internal/compress/gzip.go b/internal/compress/gzip.go index 41bfd28d48..405e730cd6 100644 --- a/internal/compress/gzip.go +++ b/internal/compress/gzip.go @@ -133,7 +133,7 @@ func (g *gzipReader) Read(p []byte) (n int, err error) { func (g *gzipReader) Close() (err error) { err = g.r.Close() if err != nil { - return errors.Wrap(g.src.Close(), err.Error()) + return errors.Join(g.src.Close(), err) } return g.src.Close() @@ -153,7 +153,7 @@ func (g *gzipWriter) Write(p []byte) (n int, err error) { func (g *gzipWriter) Close() (err error) { err = g.w.Close() if err != nil { - return errors.Wrap(g.dst.Close(), err.Error()) + return errors.Join(g.dst.Close(), err) } return g.dst.Close() diff --git a/internal/compress/gzip_test.go b/internal/compress/gzip_test.go index 7a314a47e7..eacb28c948 100644 --- a/internal/compress/gzip_test.go +++ b/internal/compress/gzip_test.go @@ -853,7 +853,7 @@ func Test_gzipReader_Close(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.New("serr"), errors.New("rerr").Error()), + err: errors.Join(errors.New("serr"), errors.New("rerr")), }, }, @@ -872,7 +872,7 @@ func Test_gzipReader_Close(t *testing.T) { }, }, want: want{ - err: errors.Wrap(nil, errors.New("rerr").Error()), + err: errors.New("rerr"), }, }, @@ -1055,7 +1055,7 @@ func Test_gzipWriter_Close(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.New("derr"), errors.New("werr").Error()), + err: errors.Join(errors.New("derr"), errors.New("werr")), }, }, @@ -1074,7 +1074,7 @@ func Test_gzipWriter_Close(t *testing.T) { }, }, want: want{ - err: errors.Wrap(nil, errors.New("werr").Error()), + err: errors.New("werr"), }, }, diff --git a/internal/compress/lz4.go b/internal/compress/lz4.go index a9e8e903f4..1c99c0089d 100644 --- a/internal/compress/lz4.go +++ b/internal/compress/lz4.go @@ -60,7 +60,7 @@ func (l *lz4Compressor) CompressVector(vector []float32) (b []byte, err error) { cerr := zw.Close() if cerr != nil { b = nil - err = errors.Wrap(err, cerr.Error()) + err = errors.Join(err, cerr) } }() @@ -142,7 +142,7 @@ func (l *lz4Writer) Write(p []byte) (n int, err error) { func (l *lz4Writer) Close() (err error) { err = l.w.Close() if err != nil { - return errors.Wrap(l.dst.Close(), err.Error()) + return errors.Join(l.dst.Close(), err) } return l.dst.Close() diff --git a/internal/compress/zstd.go b/internal/compress/zstd.go index 1980d9cfa0..093199a6f4 100644 --- a/internal/compress/zstd.go +++ b/internal/compress/zstd.go @@ -153,7 +153,7 @@ func (z *zstdWriter) Write(p []byte) (n int, err error) { func (z *zstdWriter) Close() (err error) { err = z.w.Close() if err != nil { - return errors.Wrap(z.dst.Close(), err.Error()) + return errors.Join(z.dst.Close(), err) } return z.dst.Close() diff --git a/internal/compress/zstd_test.go b/internal/compress/zstd_test.go index 83ad02e564..1df3c519ea 100644 --- a/internal/compress/zstd_test.go +++ b/internal/compress/zstd_test.go @@ -1151,7 +1151,7 @@ func Test_zstdWriter_Close(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.New("dst close err"), "w close err"), + err: errors.Join(errors.New("dst close err"), errors.New("w close err")), }, }, } diff --git a/internal/config/config.go b/internal/config/config.go index 04d64285f8..97a5525430 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -69,7 +69,7 @@ func Read(path string, cfg interface{}) (err error) { defer func() { if f != nil { if err != nil { - err = errors.Wrap(f.Close(), err.Error()) + err = errors.Join(f.Close(), err) return } err = f.Close() diff --git a/internal/db/kvs/redis/redis.go b/internal/db/kvs/redis/redis.go index c1250ee826..b492e23a03 100644 --- a/internal/db/kvs/redis/redis.go +++ b/internal/db/kvs/redis/redis.go @@ -283,7 +283,7 @@ func (rc *redisClient) ping(ctx context.Context) (r Redis, err error) { for { select { case <-pctx.Done(): - err = errors.Wrap(errors.Wrap(err, errors.ErrRedisConnectionPingFailed.Error()), pctx.Err().Error()) + err = errors.Join(err, errors.ErrRedisConnectionPingFailed, pctx.Err()) log.Error(err) return nil, err case <-tick.C: diff --git a/internal/db/kvs/redis/redis_test.go b/internal/db/kvs/redis/redis_test.go index 35ba14d277..155c33d379 100644 --- a/internal/db/kvs/redis/redis_test.go +++ b/internal/db/kvs/redis/redis_test.go @@ -216,7 +216,7 @@ func Test_redisClient_ping(t *testing.T) { }, want: want{ wantR: nil, - err: errors.Wrap(errors.Wrap(err, errors.ErrRedisConnectionPingFailed.Error()), context.DeadlineExceeded.Error()), + err: errors.Join(err, errors.ErrRedisConnectionPingFailed, context.DeadlineExceeded), }, } }(), @@ -993,7 +993,7 @@ func Test_redisClient_Connect(t *testing.T) { dialer: dialer, }, want: want{ - err: errors.Wrap(errors.Wrap(nil, errors.ErrRedisConnectionPingFailed.Error()), context.DeadlineExceeded.Error()), + err: errors.Join(nil, errors.ErrRedisConnectionPingFailed, context.DeadlineExceeded), }, checkFunc: defaultCheckFunc, } diff --git a/internal/db/nosql/cassandra/option_test.go b/internal/db/nosql/cassandra/option_test.go index 7298dba760..235c410899 100644 --- a/internal/db/nosql/cassandra/option_test.go +++ b/internal/db/nosql/cassandra/option_test.go @@ -535,7 +535,7 @@ func TestWithConnectTimeout(t *testing.T) { dur: "dummy", }, want: want{ - err: errors.NewErrCriticalOption("connectTimeout", "dummy", errors.New("invalid timeout value: dummy :timeout parse error out put failed: time: invalid duration \"dummy\"")), + err: errors.NewErrCriticalOption("connectTimeout", "dummy", errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy"))), obj: &T{}, }, }, @@ -1521,7 +1521,7 @@ func TestWithRetryPolicyMinDuration(t *testing.T) { err: errors.NewErrCriticalOption( "retryPolicyMinDuration", "dummy", - errors.New("invalid timeout value: dummy :timeout parse error out put failed: time: invalid duration \"dummy\""), + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), ), obj: &T{}, }, @@ -1613,7 +1613,7 @@ func TestWithRetryPolicyMaxDuration(t *testing.T) { err: errors.NewErrCriticalOption( "retryPolicyMaxDuration", "dummy", - errors.New("invalid timeout value: dummy :timeout parse error out put failed: time: invalid duration \"dummy\""), + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), ), obj: &T{}, }, @@ -1705,7 +1705,7 @@ func TestWithReconnectionPolicyInitialInterval(t *testing.T) { err: errors.NewErrCriticalOption( "reconnectionPolicyInitialInterval", "dummy", - errors.New("invalid timeout value: dummy :timeout parse error out put failed: time: invalid duration \"dummy\""), + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), ), obj: &T{}, }, @@ -1869,7 +1869,11 @@ func TestWithSocketKeepalive(t *testing.T) { socketKeepalive: "dummy", }, want: want{ - err: errors.NewErrCriticalOption("socketKeepalive", "dummy", errors.New("invalid timeout value: dummy :timeout parse error out put failed: time: invalid duration \"dummy\"")), + err: errors.NewErrCriticalOption( + "socketKeepalive", + "dummy", + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), + ), obj: &T{}, }, }, @@ -2973,7 +2977,7 @@ func TestWithMaxWaitSchemaAgreement(t *testing.T) { err: errors.NewErrCriticalOption( "maxWaitSchemaAgreement", "dummy", - errors.New("invalid timeout value: dummy :timeout parse error out put failed: time: invalid duration \"dummy\""), + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), ), obj: &T{}, }, @@ -3060,7 +3064,11 @@ func TestWithReconnectInterval(t *testing.T) { reconnectInterval: "dummy", }, want: want{ - err: errors.NewErrCriticalOption("reconnectInterval", "dummy", errors.New("invalid timeout value: dummy :timeout parse error out put failed: time: invalid duration \"dummy\"")), + err: errors.NewErrCriticalOption( + "reconnectInterval", + "dummy", + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), + ), obj: &T{}, }, }, @@ -3911,7 +3919,11 @@ func TestWithWriteCoalesceWaitTime(t *testing.T) { writeCoalesceWaitTime: "dummy", }, want: want{ - err: errors.NewErrCriticalOption("writeCoalesceWaitTime", "dummy", errors.New("invalid timeout value: dummy :timeout parse error out put failed: time: invalid duration \"dummy\"")), + err: errors.NewErrCriticalOption( + "writeCoalesceWaitTime", + "dummy", + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), + ), obj: &T{}, }, }, diff --git a/internal/db/rdb/mysql/mysql.go b/internal/db/rdb/mysql/mysql.go index 00ec01734a..0ec66febdf 100644 --- a/internal/db/rdb/mysql/mysql.go +++ b/internal/db/rdb/mysql/mysql.go @@ -159,13 +159,13 @@ func (m *mySQLClient) Ping(ctx context.Context) (err error) { select { case <-pctx.Done(): if err != nil { - err = errors.Wrap(errors.ErrMySQLConnectionPingFailed, err.Error()) + err = errors.Join(errors.ErrMySQLConnectionPingFailed, err) } else { err = errors.ErrMySQLConnectionPingFailed } cerr := pctx.Err() if cerr != nil { - err = errors.Wrap(err, cerr.Error()) + err = errors.Join(err, cerr) } return err case <-tick.C: diff --git a/internal/db/rdb/mysql/mysql_test.go b/internal/db/rdb/mysql/mysql_test.go index 08bd6a49ff..4b23a0137a 100644 --- a/internal/db/rdb/mysql/mysql_test.go +++ b/internal/db/rdb/mysql/mysql_test.go @@ -401,7 +401,7 @@ func Test_mySQLClient_Open(t *testing.T) { cancel() }, want: want{ - err: errors.Wrap(errors.ErrMySQLConnectionPingFailed, err.Error()), + err: errors.Join(errors.ErrMySQLConnectionPingFailed, err, context.DeadlineExceeded), }, } }(), @@ -550,7 +550,7 @@ func Test_mySQLClient_Ping(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.Wrap(errors.ErrMySQLConnectionPingFailed, err.Error()), context.DeadlineExceeded.Error()), + err: errors.Join(errors.ErrMySQLConnectionPingFailed, err, context.DeadlineExceeded), }, afterFunc: func(t *testing.T, _ args) { t.Helper() diff --git a/internal/db/storage/blob/s3/option_test.go b/internal/db/storage/blob/s3/option_test.go index d1071dc7d5..92b931f5b5 100644 --- a/internal/db/storage/blob/s3/option_test.go +++ b/internal/db/storage/blob/s3/option_test.go @@ -338,7 +338,7 @@ func TestWithMaxPartSize(t *testing.T) { maxPartSize: 0, }, err: func() (err error) { - err = errors.Wrap(errors.New("byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, G, GiB, or GB"), errors.ErrParseUnitFailed("a").Error()) + err = errors.Join(errors.New("byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, G, GiB, or GB"), errors.ErrParseUnitFailed("a")) return }(), }, @@ -435,7 +435,7 @@ func TestWithMaxChunkSize(t *testing.T) { maxChunkSize: 0, }, err: func() (err error) { - err = errors.Wrap(errors.New("byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, G, GiB, or GB"), errors.ErrParseUnitFailed("a").Error()) + err = errors.Join(errors.New("byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, G, GiB, or GB"), errors.ErrParseUnitFailed("a")) return }(), }, diff --git a/internal/errgroup/group.go b/internal/errgroup/group.go index 38225c8586..997f14511a 100644 --- a/internal/errgroup/group.go +++ b/internal/errgroup/group.go @@ -174,7 +174,7 @@ func (g *group) Wait() error { default: g.err = g.errs[0] for _, err := range g.errs[1:] { - g.err = errors.Wrap(g.err, err.Error()) + g.err = errors.Join(g.err, err) } } g.mu.RUnlock() diff --git a/internal/errgroup/group_test.go b/internal/errgroup/group_test.go index 506237cda5..776f998612 100644 --- a/internal/errgroup/group_test.go +++ b/internal/errgroup/group_test.go @@ -766,7 +766,7 @@ func Test_group_Wait(t *testing.T) { }, }, want: want{ - err: errors.Wrap(errors.New("err1"), errors.New("err2").Error()), + err: errors.Join(errors.New("err1"), errors.New("err2")), }, }, } diff --git a/internal/file/file.go b/internal/file/file.go index 64437dc047..f658479c6e 100644 --- a/internal/file/file.go +++ b/internal/file/file.go @@ -45,7 +45,7 @@ func Open(path string, flg int, perm fs.FileMode) (file *os.File, err error) { defer func() { if err != nil && file != nil { - err = errors.Wrap(file.Close(), err.Error()) + err = errors.Join(file.Close(), err) file = nil } }() @@ -124,7 +124,7 @@ func doMoveDir(ctx context.Context, src, dst string, rollback bool) (err error) if err != nil && Exists(dst) { err = errors.ErrFailedToRemoveDir(err, dst, nil) if rollback { - err = errors.Wrap(doMoveDir(ctx, tmpPath, dst, false), errors.Wrapf(err, "trying to recover temporary file %s to rollback previous operation", tmpPath).Error()) + err = errors.Join(doMoveDir(ctx, tmpPath, dst, false), errors.Wrapf(err, "trying to recover temporary file %s to rollback previous operation", tmpPath)) } log.Warn(err) return err @@ -141,7 +141,7 @@ func doMoveDir(ctx context.Context, src, dst string, rollback bool) (err error) if err != nil { err = errors.ErrFailedToCopyDir(err, src, dst, fi, nil) if rollback { - err = errors.Wrap(doMoveDir(ctx, tmpPath, dst, false), errors.Wrapf(err, "trying to recover temporary file %s to rollback previous operation", tmpPath).Error()) + err = errors.Join(doMoveDir(ctx, tmpPath, dst, false), errors.Wrapf(err, "trying to recover temporary file %s to rollback previous operation", tmpPath)) } log.Warn(err) return err @@ -181,7 +181,7 @@ func CopyDir(ctx context.Context, src, dst string) (err error) { if err != nil { fi, ierr := info.Info() if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } err = errors.ErrFailedToWalkDir(err, src, childPath, nil, fi) log.Warn(err) @@ -202,7 +202,7 @@ func CopyDir(ctx context.Context, src, dst string) (err error) { return nil }) if err != nil { - return errors.Wrap(eg.Wait(), err.Error()) + return errors.Join(eg.Wait(), err) } return eg.Wait() } @@ -227,9 +227,9 @@ func CopyFileWithPerm(ctx context.Context, src, dst string, perm fs.FileMode) (n exist, fi, err := ExistsWithDetail(src) switch { case !exist, fi == nil, fi.Size() == 0, fi.IsDir(): - return 0, errors.Wrap(err, errors.ErrFileNotFound(src).Error()) + return 0, errors.Join(err, errors.ErrFileNotFound(src)) case err != nil && (!errors.Is(err, fs.ErrExist) || errors.Is(err, fs.ErrNotExist)): - return 0, errors.Wrap(errors.ErrFileNotFound(src), err.Error()) + return 0, errors.Join(errors.ErrFileNotFound(src), err) case fi != nil && !fi.Mode().IsRegular(): return 0, errors.ErrNonRegularFile(src, fi) case err != nil: @@ -246,7 +246,7 @@ func CopyFileWithPerm(ctx context.Context, src, dst string, perm fs.FileMode) (n if sf != nil { derr := sf.Close() if derr != nil { - err = errors.Wrap(err, errors.ErrFailedToCloseFile(derr, src, fi).Error()) + err = errors.Join(err, errors.ErrFailedToCloseFile(derr, src, fi)) } } }() @@ -280,7 +280,7 @@ func writeFileWithContext(ctx context.Context, target string, r io.Reader, flg i case err == nil, exist, fi != nil && fi.Size() != 0, fi != nil && fi.IsDir(): err = errors.ErrFileAlreadyExists(target) case err != nil && !errors.Is(err, fs.ErrNotExist), err != nil && errors.Is(err, fs.ErrExist): - err = errors.Wrap(errors.ErrFileAlreadyExists(target), err.Error()) + err = errors.Join(errors.ErrFileAlreadyExists(target), err) case err != nil: log.Warn(err) } @@ -300,7 +300,7 @@ func writeFileWithContext(ctx context.Context, target string, r io.Reader, flg i if f != nil { derr := f.Close() if derr != nil { - err = errors.Wrap(err, errors.ErrFailedToCloseFile(derr, target, fi).Error()) + err = errors.Join(err, errors.ErrFailedToCloseFile(derr, target, fi)) } } }() @@ -332,7 +332,7 @@ func ReadDir(path string) (dirs []fs.DirEntry, err error) { if f != nil { derr := f.Close() if derr != nil { - err = errors.Wrap(err, errors.ErrFailedToCloseFile(derr, path, nil).Error()) + err = errors.Join(err, errors.ErrFailedToCloseFile(derr, path, nil)) } } }() @@ -351,7 +351,7 @@ func ReadFile(path string) (n []byte, err error) { if f != nil { derr := f.Close() if derr != nil { - err = errors.Wrap(err, errors.ErrFailedToCloseFile(derr, path, nil).Error()) + err = errors.Join(err, errors.ErrFailedToCloseFile(derr, path, nil)) } } }() @@ -393,7 +393,7 @@ func MkdirAll(path string, perm fs.FileMode) (err error) { } rerr = os.RemoveAll(path) if rerr != nil { - err = errors.Wrap(err, rerr.Error()) + err = errors.Join(err, rerr) } } if err != nil { @@ -403,16 +403,16 @@ func MkdirAll(path string, perm fs.FileMode) (err error) { if merr == nil { return nil } - err = errors.Wrap(merr, err.Error()) + err = errors.Join(merr, err) if err != nil { if errors.Is(err, fs.ErrPermission) { rerr = os.RemoveAll(path) if rerr != nil { - err = errors.Wrap(err, errors.ErrFailedToRemoveDir(rerr, path, fi).Error()) + err = errors.Join(err, errors.ErrFailedToRemoveDir(rerr, path, fi)) } merr = os.MkdirAll(path, fs.ModePerm) if merr != nil { - err = errors.Wrap(err, errors.ErrFailedToMkdir(merr, path, fi).Error()) + err = errors.Join(err, errors.ErrFailedToMkdir(merr, path, fi)) } } log.Warn(err) diff --git a/internal/log/zap/zap.go b/internal/log/zap/zap.go index 58a160cf01..86e3ad1540 100644 --- a/internal/log/zap/zap.go +++ b/internal/log/zap/zap.go @@ -94,7 +94,7 @@ func (l *logger) initialize(sinkPath, errSinkPath string) (err error) { func (l *logger) Close() error { err := l.logger.Sync() if err != nil { - return errors.Wrap(l.sugar.Sync(), err.Error()) + return errors.Join(l.sugar.Sync(), err) } return l.sugar.Sync() diff --git a/internal/net/control/control.go b/internal/net/control/control.go index b9c03088fe..d8f507b7e3 100644 --- a/internal/net/control/control.go +++ b/internal/net/control/control.go @@ -103,50 +103,50 @@ func (ctrl *control) controlFunc(network, address string, c syscall.RawConn) (er if SO_REUSEPORT != 0 { ierr = SetsockoptInt(f, SOL_SOCKET, SO_REUSEPORT, boolint(ctrl.reusePort)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if SO_REUSEADDR != 0 { ierr = SetsockoptInt(f, SOL_SOCKET, SO_REUSEADDR, boolint(ctrl.reuseAddr)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if isTCP(network) { if TCP_FASTOPEN != 0 { ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_FASTOPEN, boolint(ctrl.tcpFastOpen)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if TCP_FASTOPEN_CONNECT != 0 { ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, boolint(ctrl.tcpFastOpen)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if TCP_NODELAY != 0 { ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_NODELAY, boolint(ctrl.tcpNoDelay)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if TCP_CORK != 0 { ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_CORK, boolint(ctrl.tcpCork)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if TCP_QUICKACK != 0 { ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_QUICKACK, boolint(ctrl.tcpQuickAck)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if TCP_DEFER_ACCEPT != 0 { ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_DEFER_ACCEPT, boolint(ctrl.tcpDeferAccept)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } } @@ -160,33 +160,33 @@ func (ctrl *control) controlFunc(network, address string, c syscall.RawConn) (er if sol != 0 && trans != 0 { ierr = SetsockoptInt(f, sol, trans, boolint(ctrl.ipTransparent)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if sol != 0 && rda != 0 { ierr = SetsockoptInt(f, sol, rda, boolint(ctrl.ipRecoverDestinationAddr)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if SO_KEEPALIVE != 0 { ierr = SetsockoptInt(f, SOL_SOCKET, SO_KEEPALIVE, boolint(ctrl.keepAlive > 0)) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if ctrl.keepAlive > 0 && isTCP(network) { if TCP_KEEPINTVL != 0 { ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_KEEPINTVL, ctrl.keepAlive) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } if TCP_KEEPIDLE != 0 { ierr = SetsockoptInt(f, IPPROTO_TCP, TCP_KEEPIDLE, ctrl.keepAlive) if ierr != nil { - err = errors.Wrap(err, ierr.Error()) + err = errors.Join(err, ierr) } } } diff --git a/internal/net/dialer.go b/internal/net/dialer.go index 31af53960b..39251a9c7b 100644 --- a/internal/net/dialer.go +++ b/internal/net/dialer.go @@ -316,7 +316,7 @@ func (d *dialer) dial(ctx context.Context, network, addr string) (conn Conn, err defer func(conn Conn) { if conn != nil { if err != nil { - err = errors.Wrap(conn.Close(), err.Error()) + err = errors.Join(conn.Close(), err) return } err = conn.Close() @@ -414,7 +414,7 @@ func (d *dialer) tlsHandshake(ctx context.Context, conn Conn, network, addr stri defer func(conn Conn) { if conn != nil { if err != nil { - err = errors.Wrap(conn.Close(), err.Error()) + err = errors.Join(conn.Close(), err) return } err = conn.Close() diff --git a/internal/net/grpc/client.go b/internal/net/grpc/client.go index 8531a4af52..ff39dd1c4f 100644 --- a/internal/net/grpc/client.go +++ b/internal/net/grpc/client.go @@ -211,7 +211,7 @@ func (g *gRPCClient) StartConnectionMonitor(ctx context.Context) (<-chan error, select { case <-ctx.Done(): if err != nil { - return errors.Wrap(ctx.Err(), err.Error()) + return errors.Join(ctx.Err(), err) } return ctx.Err() case <-prTick.C: @@ -912,7 +912,7 @@ func (g *gRPCClient) Connect(ctx context.Context, addr string, dopts ...DialOpti derr := g.Disconnect(ctx, addr) if derr != nil && !errors.Is(derr, errors.ErrGRPCClientConnNotFound(addr)) { log.Warnf("failed to disconnect unhealthy pool addr= %s\terror= %s", addr, err.Error()) - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } return nil, err } @@ -923,7 +923,7 @@ func (g *gRPCClient) Connect(ctx context.Context, addr string, dopts ...DialOpti derr := g.Disconnect(ctx, addr) if derr != nil && !errors.Is(derr, errors.ErrGRPCClientConnNotFound(addr)) { log.Warnf("failed to disconnect unhealthy pool addr= %s\terror= %s", addr, err.Error()) - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } return nil, err } @@ -1021,7 +1021,7 @@ func (g *gRPCClient) Close(ctx context.Context) (err error) { g.conns.Range(func(addr string, p pool.Conn) bool { derr := g.Disconnect(ctx, addr) if derr != nil && !errors.Is(derr, errors.ErrGRPCClientConnNotFound(addr)) { - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } return true }) diff --git a/internal/net/grpc/pool/pool.go b/internal/net/grpc/pool/pool.go index a89a85b04e..fba9f0d267 100644 --- a/internal/net/grpc/pool/pool.go +++ b/internal/net/grpc/pool/pool.go @@ -143,7 +143,7 @@ func New(ctx context.Context, opts ...Option) (c Conn, err error) { if conn != nil { cerr := conn.Close() if cerr != nil && !errors.Is(cerr, grpc.ErrClientConnClosing) { - return nil, errors.Wrap(err, cerr.Error()) + return nil, errors.Join(err, cerr) } } return nil, err @@ -305,7 +305,7 @@ func (p *pool) refreshConn(ctx context.Context, idx int, pc *poolConn, addr stri })) } } - return errors.Wrap(err, errors.ErrInvalidGRPCClientConn(addr).Error()) + return errors.Join(err, errors.ErrInvalidGRPCClientConn(addr)) } p.store(idx, &poolConn{ conn: conn, @@ -441,7 +441,7 @@ func (p *pool) Disconnect() (err error) { }) p.flush() for _, e := range emap { - err = errors.Wrap(err, e.Error()) + err = errors.Join(err, e) } return err } @@ -455,7 +455,7 @@ func (p *pool) dial(ctx context.Context, addr string) (conn *ClientConn, err err if conn != nil { cerr := conn.Close() if cerr != nil && !errors.Is(cerr, grpc.ErrClientConnClosing) { - err = errors.Wrap(err, cerr.Error()) + err = errors.Join(err, cerr) } } log.Debugf("failed to dial gRPC connection to %s,\terror: %v", addr, err) @@ -465,7 +465,7 @@ func (p *pool) dial(ctx context.Context, addr string) (conn *ClientConn, err err if conn != nil { err = conn.Close() if err != nil && !errors.Is(err, grpc.ErrClientConnClosing) { - err = errors.Wrapf(errors.ErrGRPCClientConnNotFound(addr), err.Error()) + err = errors.Join(errors.ErrGRPCClientConnNotFound(addr), err) } else { err = errors.ErrGRPCClientConnNotFound(addr) } @@ -708,7 +708,7 @@ func (pc *poolConn) Close(ctx context.Context, delay time.Duration) error { if ctx.Err() != nil && !errors.Is(ctx.Err(), context.DeadlineExceeded) && !errors.Is(ctx.Err(), context.Canceled) { - return errors.Wrap(err, ctx.Err().Error()) + return errors.Join(err, ctx.Err()) } return err } diff --git a/internal/net/grpc/stream.go b/internal/net/grpc/stream.go index 0f96b370cb..087ef2d1af 100644 --- a/internal/net/grpc/stream.go +++ b/internal/net/grpc/stream.go @@ -72,6 +72,9 @@ func BidirectionalStream[Q any, R any](ctx context.Context, stream ServerStream, if errs == nil { errs = err } else { + // FIXME: It should have been errors.Join here, but it remains errors.Wrap because the bench/agent/stream tests will fail. + // The reason is likely that when it's changed to errors.Join, status.ParseError cannot parse errors correctly, + // but this needs to be investigated further. errs = errors.Wrap(err, errs.Error()) } return true @@ -192,7 +195,7 @@ func BidirectionalStreamClient(stream ClientStream, defer func() { if err != nil { - err = errors.Wrap(stream.CloseSend(), err.Error()) + err = errors.Join(stream.CloseSend(), err) } else { err = stream.CloseSend() } @@ -209,7 +212,7 @@ func BidirectionalStreamClient(stream ClientStream, err = stream.CloseSend() cancel() if err != nil { - return errors.Wrap(eg.Wait(), err.Error()) + return errors.Join(eg.Wait(), err) } return eg.Wait() } diff --git a/internal/net/http/client/option_test.go b/internal/net/http/client/option_test.go index a130f8705e..741b3e28e1 100644 --- a/internal/net/http/client/option_test.go +++ b/internal/net/http/client/option_test.go @@ -254,7 +254,11 @@ func TestWithTLSHandshakeTimeout(t *testing.T) { obj: &T{ Transport: &http.Transport{}, }, - err: errors.NewErrCriticalOption("TLSHandshakeTimeout", "dummy", errors.New("invalid timeout value: dummy\t:timeout parse error out put failed: time: invalid duration \"dummy\"")), + err: errors.NewErrCriticalOption( + "TLSHandshakeTimeout", + "dummy", + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), + ), }, }, { @@ -759,7 +763,11 @@ func TestWithIdleConnTimeout(t *testing.T) { obj: &T{ Transport: &http.Transport{}, }, - err: errors.NewErrCriticalOption("idleConnTimeout", "dummy", errors.New("invalid timeout value: dummy\t:timeout parse error out put failed: time: invalid duration \"dummy\"")), + err: errors.NewErrCriticalOption( + "idleConnTimeout", + "dummy", + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), + ), }, }, { @@ -852,7 +860,11 @@ func TestWithResponseHeaderTimeout(t *testing.T) { obj: &T{ Transport: &http.Transport{}, }, - err: errors.NewErrCriticalOption("responseHeaderTimeout", "dummy", errors.New("invalid timeout value: dummy\t:timeout parse error out put failed: time: invalid duration \"dummy\"")), + err: errors.NewErrCriticalOption( + "responseHeaderTimeout", + "dummy", + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), + ), }, }, { @@ -945,7 +957,11 @@ func TestWithExpectContinueTimeout(t *testing.T) { obj: &T{ Transport: &http.Transport{}, }, - err: errors.NewErrCriticalOption("expectContinueTimeout", "dummy", errors.New("invalid timeout value: dummy\t:timeout parse error out put failed: time: invalid duration \"dummy\"")), + err: errors.NewErrCriticalOption( + "expectContinueTimeout", + "dummy", + errors.Join(errors.New("time: invalid duration \"dummy\""), errors.ErrTimeoutParseFailed("dummy")), + ), }, }, { diff --git a/internal/net/http/middleware/timeout.go b/internal/net/http/middleware/timeout.go index c290171873..001f9fe917 100644 --- a/internal/net/http/middleware/timeout.go +++ b/internal/net/http/middleware/timeout.go @@ -82,7 +82,7 @@ func (t *timeout) Wrap(h rest.Func) rest.Func { if err != nil { select { case <-ctx.Done(): - return http.StatusRequestTimeout, errors.ErrHandlerTimeout(errors.Wrap(ctx.Err(), err.Error()), time.Duration(fastime.UnixNanoNow()-start)) + return http.StatusRequestTimeout, errors.ErrHandlerTimeout(errors.Join(ctx.Err(), err), time.Duration(fastime.UnixNanoNow()-start)) case code = <-sch: } err = errors.ErrHandler(err) diff --git a/internal/net/http/transport/roundtrip.go b/internal/net/http/transport/roundtrip.go index 503c25f96d..45dfcfe9d3 100644 --- a/internal/net/http/transport/roundtrip.go +++ b/internal/net/http/transport/roundtrip.go @@ -76,7 +76,7 @@ func (e *ert) doRoundTrip(req *http.Request) (res *http.Response, err error) { if res != nil { // just in case we check the response as it depends on RoundTrip impl. closeBody(res.Body) if retryableStatusCode(res.StatusCode) { - return nil, errors.Wrap(errors.ErrTransportRetryable, err.Error()) + return nil, errors.Join(errors.ErrTransportRetryable, err) } } return nil, err diff --git a/internal/observability/observability.go b/internal/observability/observability.go index 80fe8e01de..f80fcb92d2 100644 --- a/internal/observability/observability.go +++ b/internal/observability/observability.go @@ -156,7 +156,7 @@ func (o *observability) Stop(ctx context.Context) (werr error) { for _, ex := range o.exporters { if err := ex.Stop(ctx); err != nil { log.Error(err) - werr = errors.Wrap(werr, err.Error()) + werr = errors.Join(werr, err) } } return werr diff --git a/internal/safety/safety.go b/internal/safety/safety.go index f073c422bc..34b2a29d31 100644 --- a/internal/safety/safety.go +++ b/internal/safety/safety.go @@ -52,7 +52,7 @@ func recoverFn(fn func() error, withPanic bool) func() error { case string: err = errors.ErrPanicString(err, x) case error: - err = errors.Wrap(err, x.Error()) + err = errors.Join(err, x) default: err = errors.ErrPanicRecovered(err, x) } diff --git a/internal/servers/server/server.go b/internal/servers/server/server.go index 43ba7eb430..8e32ea7deb 100644 --- a/internal/servers/server/server.go +++ b/internal/servers/server/server.go @@ -390,7 +390,7 @@ func (s *server) Shutdown(ctx context.Context) (rerr error) { defer func() { err := os.RemoveAll(s.socketPath) if err != nil { - rerr = errors.Wrap(rerr, err.Error()) + rerr = errors.Join(rerr, err) } }() } @@ -403,12 +403,12 @@ func (s *server) Shutdown(ctx context.Context) (rerr error) { s.http.srv.SetKeepAlivesEnabled(false) err := s.http.srv.Shutdown(sctx) if err != nil && err != http.ErrServerClosed && err != grpc.ErrServerStopped { - rerr = errors.Wrap(rerr, err.Error()) + rerr = errors.Join(rerr, err) } err = sctx.Err() if err != nil && err != context.Canceled { - rerr = errors.Wrap(rerr, err.Error()) + rerr = errors.Join(rerr, err) } case GRPC: diff --git a/internal/timeutil/time.go b/internal/timeutil/time.go index 60a646c907..a96923d1ee 100644 --- a/internal/timeutil/time.go +++ b/internal/timeutil/time.go @@ -29,7 +29,7 @@ func Parse(t string) (time.Duration, error) { } dur, err := time.ParseDuration(t) if err != nil { - return 0, errors.Wrap(err, errors.ErrTimeoutParseFailed(t).Error()) + return 0, errors.Join(err, errors.ErrTimeoutParseFailed(t)) } return dur, nil } diff --git a/internal/unit/unit.go b/internal/unit/unit.go index daca9e58a0..d4a2490707 100644 --- a/internal/unit/unit.go +++ b/internal/unit/unit.go @@ -30,7 +30,7 @@ func ParseBytes(bs string) (bytes uint64, err error) { bytes, err = bytefmt.ToBytes(bs) if err != nil { - return 0, errors.Wrap(err, errors.ErrParseUnitFailed(bs).Error()) + return 0, errors.Join(err, errors.ErrParseUnitFailed(bs)) } return bytes, nil } diff --git a/internal/unit/unit_test.go b/internal/unit/unit_test.go index 73d2730209..4faab56704 100644 --- a/internal/unit/unit_test.go +++ b/internal/unit/unit_test.go @@ -87,7 +87,7 @@ func TestParseBytes(t *testing.T) { want: want{ wantBytes: 0, err: func() (err error) { - err = errors.Wrap(errors.New("byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, G, GiB, or GB"), errors.ErrParseUnitFailed("a").Error()) + err = errors.Join(errors.New("byte quantity must be a positive integer with a unit of measurement like M, MB, MiB, G, GiB, or GB"), errors.ErrParseUnitFailed("a")) return }(), }, diff --git a/internal/worker/worker.go b/internal/worker/worker.go index 215283e4a7..3118903071 100644 --- a/internal/worker/worker.go +++ b/internal/worker/worker.go @@ -142,7 +142,7 @@ func (w *worker) startJobLoop(ctx context.Context) <-chan error { select { case <-ctx.Done(): if err = ctx.Err(); err != nil { - return errors.Wrap(eg.Wait(), err.Error()) + return errors.Join(eg.Wait(), err) } return eg.Wait() case limitation <- struct{}{}: diff --git a/pkg/agent/core/ngt/handler/grpc/insert_test.go b/pkg/agent/core/ngt/handler/grpc/insert_test.go index 354669bc7d..3bc376223a 100644 --- a/pkg/agent/core/ngt/handler/grpc/insert_test.go +++ b/pkg/agent/core/ngt/handler/grpc/insert_test.go @@ -2713,9 +2713,8 @@ func Test_server_MultiInsert(t *testing.T) { svcOpts []service.Option } type want struct { - wantRes *payload.Object_Locations - err error - containErr []error // check the function output error contain one of the error or not + wantRes *payload.Object_Locations + err error } type test struct { name string @@ -2758,11 +2757,15 @@ func Test_server_MultiInsert(t *testing.T) { } ) - genAlreadyExistsErr := func(uuid string, req *payload.Insert_MultiRequest, name, ip string) error { - return status.WrapWithAlreadyExists(fmt.Sprintf("MultiInsert API uuids [%v] already exists", uuid), - errors.ErrUUIDAlreadyExists(uuid), + genAlreadyExistsJoinedErr := func(uuids []string, req *payload.Insert_MultiRequest, name, ip string) error { + var joindErr error + for _, uuid := range uuids { + errors.Join(joindErr, errors.ErrUUIDAlreadyExists(uuid)) + } + return status.WrapWithAlreadyExists(fmt.Sprintf("MultiInsert API uuids %v already exists", uuids), + joindErr, &errdetails.RequestInfo{ - RequestId: uuid, + RequestId: strings.Join(uuids, ", "), ServingData: errdetails.Serialize(req), }, &errdetails.ResourceInfo{ @@ -2772,21 +2775,8 @@ func Test_server_MultiInsert(t *testing.T) { } defaultCheckFunc := func(w want, gotRes *payload.Object_Locations, err error) error { - if w.containErr == nil { - if !errors.Is(err, w.err) { - return errors.Errorf("got_error: \"%v\",\n\t\t\t\twant: \"%v\"", err, w.err) - } - } else { - exist := false - for _, e := range w.containErr { - if errors.Is(err, e) { - exist = true - break - } - } - if !exist { - return errors.Errorf("got_error: \"%v\",\n\t\t\t\tshould contain one of the error: \"%v\"", err, w.containErr) - } + if !errors.Is(err, w.err) { + return errors.Errorf("got_error: \"%v\",\n\t\t\t\twant: \"%v\"", err, w.err) } if !reflect.DeepEqual(gotRes, w.wantRes) { return errors.Errorf("got: \"%#v\",\n\t\t\t\twant: \"%#v\"", gotRes, w.wantRes) @@ -5011,10 +5001,7 @@ func Test_server_MultiInsert(t *testing.T) { } }, want: want{ - containErr: []error{ - genAlreadyExistsErr(req.Requests[0].Vector.Id, req, name, ip), - genAlreadyExistsErr(req.Requests[1].Vector.Id, req, name, ip), - }, + err: genAlreadyExistsJoinedErr([]string{req.Requests[0].Vector.Id, req.Requests[1].Vector.Id}, req, name, ip), }, } }(), @@ -5025,10 +5012,11 @@ func Test_server_MultiInsert(t *testing.T) { t.Error(err) } - wantErrs := make([]error, 100) - for i := 0; i < len(req.Requests); i++ { - wantErrs[i] = genAlreadyExistsErr(req.Requests[i].Vector.Id, req, name, ip) + ids := make([]string, 0, len(req.Requests)) + for _, r := range req.Requests { + ids = append(ids, r.Vector.Id) } + wantErr := genAlreadyExistsJoinedErr(ids, req, name, ip) return test{ name: "Decision Table Testing case 4.2: Fail to MultiInsert with all existed ID when SkipStrictExistCheck is false", @@ -5068,7 +5056,7 @@ func Test_server_MultiInsert(t *testing.T) { } }, want: want{ - containErr: wantErrs, + err: wantErr, }, } }(), @@ -5118,10 +5106,7 @@ func Test_server_MultiInsert(t *testing.T) { } }, want: want{ - containErr: []error{ - genAlreadyExistsErr(req.Requests[0].Vector.Id, req, name, ip), - genAlreadyExistsErr(req.Requests[1].Vector.Id, req, name, ip), - }, + err: genAlreadyExistsJoinedErr([]string{req.Requests[0].Vector.Id, req.Requests[1].Vector.Id}, req, name, ip), }, } }(), @@ -5132,10 +5117,11 @@ func Test_server_MultiInsert(t *testing.T) { t.Error(err) } - wantErrs := make([]error, 100) - for i := 0; i < len(req.Requests); i++ { - wantErrs[i] = genAlreadyExistsErr(req.Requests[i].Vector.Id, req, name, ip) + ids := make([]string, 0, len(req.Requests)) + for _, r := range req.Requests { + ids = append(ids, r.Vector.Id) } + wantErr := genAlreadyExistsJoinedErr(ids, req, name, ip) return test{ name: "Decision Table Testing case 4.4: Fail to MultiInsert with all existed ID when SkipStrictExistCheck is true", @@ -5175,7 +5161,7 @@ func Test_server_MultiInsert(t *testing.T) { } }, want: want{ - containErr: wantErrs, + err: wantErr, }, } }(), @@ -5402,10 +5388,7 @@ func Test_server_MultiInsert(t *testing.T) { } }, want: want{ - containErr: []error{ - genAlreadyExistsErr(req.Requests[0].Vector.Id, req, name, ip), - genAlreadyExistsErr(req.Requests[1].Vector.Id, req, name, ip), - }, + err: genAlreadyExistsJoinedErr([]string{req.Requests[0].Vector.Id, req.Requests[1].Vector.Id}, req, name, ip), }, } }(), @@ -5416,10 +5399,11 @@ func Test_server_MultiInsert(t *testing.T) { t.Error(err) } - wantErrs := make([]error, 100) - for i := 0; i < len(req.Requests); i++ { - wantErrs[i] = genAlreadyExistsErr(req.Requests[i].Vector.Id, req, name, ip) + ids := make([]string, 0, len(req.Requests)) + for _, r := range req.Requests { + ids = append(ids, r.Vector.Id) } + wantErr := genAlreadyExistsJoinedErr(ids, req, name, ip) return test{ name: "Decision Table Testingcase 6.2: Fail to MultiInsert with all existed ID & vector when SkipStrictExistCheck is false", @@ -5452,7 +5436,7 @@ func Test_server_MultiInsert(t *testing.T) { } }, want: want{ - containErr: wantErrs, + err: wantErr, }, } }(), @@ -5495,10 +5479,7 @@ func Test_server_MultiInsert(t *testing.T) { } }, want: want{ - containErr: []error{ - genAlreadyExistsErr(req.Requests[0].Vector.Id, req, name, ip), - genAlreadyExistsErr(req.Requests[1].Vector.Id, req, name, ip), - }, + err: genAlreadyExistsJoinedErr([]string{req.Requests[0].Vector.Id, req.Requests[1].Vector.Id}, req, name, ip), }, } }(), @@ -5509,10 +5490,11 @@ func Test_server_MultiInsert(t *testing.T) { t.Error(err) } - wantErrs := make([]error, 100) - for i := 0; i < len(req.Requests); i++ { - wantErrs[i] = genAlreadyExistsErr(req.Requests[i].Vector.Id, req, name, ip) + ids := make([]string, 0, len(req.Requests)) + for _, r := range req.Requests { + ids = append(ids, r.Vector.Id) } + wantErr := genAlreadyExistsJoinedErr(ids, req, name, ip) return test{ name: "Decision Table Testing case 6.4: Fail to MultiInsert with all existed ID & vector when SkipStrictExistCheck is true", @@ -5545,7 +5527,7 @@ func Test_server_MultiInsert(t *testing.T) { } }, want: want{ - containErr: wantErrs, + err: wantErr, }, } }(), diff --git a/pkg/agent/core/ngt/handler/grpc/linear_search.go b/pkg/agent/core/ngt/handler/grpc/linear_search.go index 56017c1b25..f26c48b5b3 100644 --- a/pkg/agent/core/ngt/handler/grpc/linear_search.go +++ b/pkg/agent/core/ngt/handler/grpc/linear_search.go @@ -434,7 +434,7 @@ func (s *server) MultiLinearSearch(ctx context.Context, reqs *payload.Search_Mul if errs == nil { errs = err } else { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } mu.Unlock() return nil @@ -508,7 +508,7 @@ func (s *server) MultiLinearSearchByID(ctx context.Context, reqs *payload.Search if errs == nil { errs = err } else { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } mu.Unlock() return nil diff --git a/pkg/agent/core/ngt/handler/grpc/search.go b/pkg/agent/core/ngt/handler/grpc/search.go index 788d23f3e3..328806f7e7 100644 --- a/pkg/agent/core/ngt/handler/grpc/search.go +++ b/pkg/agent/core/ngt/handler/grpc/search.go @@ -439,7 +439,7 @@ func (s *server) MultiSearch(ctx context.Context, reqs *payload.Search_MultiRequ if errs == nil { errs = err } else { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } mu.Unlock() return nil @@ -513,7 +513,7 @@ func (s *server) MultiSearchByID(ctx context.Context, reqs *payload.Search_Multi if errs == nil { errs = err } else { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } mu.Unlock() return nil diff --git a/pkg/agent/core/ngt/handler/grpc/upsert.go b/pkg/agent/core/ngt/handler/grpc/upsert.go index b7aeb8eadd..e94849d1ff 100644 --- a/pkg/agent/core/ngt/handler/grpc/upsert.go +++ b/pkg/agent/core/ngt/handler/grpc/upsert.go @@ -271,7 +271,7 @@ func (s *server) MultiUpsert(ctx context.Context, reqs *payload.Upsert_MultiRequ if errs == nil { errs = err } else { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } mu.Unlock() } @@ -288,7 +288,7 @@ func (s *server) MultiUpsert(ctx context.Context, reqs *payload.Upsert_MultiRequ if errs == nil { errs = err } else { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } mu.Unlock() } diff --git a/pkg/agent/core/ngt/service/ngt.go b/pkg/agent/core/ngt/service/ngt.go index 730f202a52..95da161fe0 100644 --- a/pkg/agent/core/ngt/service/ngt.go +++ b/pkg/agent/core/ngt/service/ngt.go @@ -496,7 +496,7 @@ func (n *ngt) loadKVS(ctx context.Context, path string, timeout time.Duration) ( if f != nil { derr := f.Close() if derr != nil { - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } } }() @@ -523,7 +523,7 @@ func (n *ngt) loadKVS(ctx context.Context, path string, timeout time.Duration) ( if ft != nil { derr := ft.Close() if derr != nil { - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } } }() @@ -605,7 +605,7 @@ func (n *ngt) Start(ctx context.Context) <-chan error { err = n.CreateIndex(ctx, n.poolSize) if err != nil && !errors.Is(err, errors.ErrUncommittedIndexNotFound) { ech <- err - return errors.Wrap(ctx.Err(), err.Error()) + return errors.Join(ctx.Err(), err) } return ctx.Err() case <-tick.C: @@ -772,7 +772,7 @@ func (n *ngt) insertMultiple(vecs map[string][]float32, now int64, validation bo ierr := n.insert(uuid, vec, now, validation) if ierr != nil { if err != nil { - err = errors.Wrap(ierr, err.Error()) + err = errors.Join(ierr, err) } else { err = ierr } @@ -873,7 +873,7 @@ func (n *ngt) deleteMultiple(uuids []string, now int64, validation bool) (err er ierr := n.delete(uuid, now, validation) if ierr != nil { if err != nil { - err = errors.Wrap(ierr, err.Error()) + err = errors.Join(ierr, err) } else { err = ierr } @@ -1129,7 +1129,7 @@ func (n *ngt) saveIndex(ctx context.Context) (err error) { if f != nil { derr := f.Close() if derr != nil { - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } } }() @@ -1157,7 +1157,7 @@ func (n *ngt) saveIndex(ctx context.Context) (err error) { if ft != nil { derr := ft.Close() if derr != nil { - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } } }() @@ -1193,7 +1193,7 @@ func (n *ngt) saveIndex(ctx context.Context) (err error) { if f != nil { derr := f.Close() if derr != nil { - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } } }() @@ -1408,7 +1408,7 @@ func (n *ngt) Close(ctx context.Context) (err error) { !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) { if err != nil { - err = errors.Wrap(cerr, err.Error()) + err = errors.Join(cerr, err) } else { err = cerr } @@ -1419,7 +1419,7 @@ func (n *ngt) Close(ctx context.Context) (err error) { !errors.Is(err, context.Canceled) && !errors.Is(err, context.DeadlineExceeded) { if err != nil { - err = errors.Wrap(serr, err.Error()) + err = errors.Join(serr, err) } else { err = serr } diff --git a/pkg/agent/core/ngt/service/option_test.go b/pkg/agent/core/ngt/service/option_test.go index 01a25d8b42..326264012d 100644 --- a/pkg/agent/core/ngt/service/option_test.go +++ b/pkg/agent/core/ngt/service/option_test.go @@ -316,7 +316,7 @@ func TestWithAutoIndexCheckDuration(t *testing.T) { }, want: want{ obj: &T{}, - err: errors.New("invalid timeout value: 5ss\t:timeout parse error out put failed: time: unknown unit \"ss\" in duration \"5ss\""), + err: errors.Join(errors.New("time: unknown unit \"ss\" in duration \"5ss\""), errors.ErrTimeoutParseFailed("5ss")), }, }, } @@ -401,7 +401,7 @@ func TestWithAutoIndexDurationLimit(t *testing.T) { }, want: want{ obj: &T{}, - err: errors.New("invalid timeout value: 5ss\t:timeout parse error out put failed: time: unknown unit \"ss\" in duration \"5ss\""), + err: errors.Join(errors.New("time: unknown unit \"ss\" in duration \"5ss\""), errors.ErrTimeoutParseFailed("5ss")), }, }, } @@ -486,7 +486,7 @@ func TestWithAutoSaveIndexDuration(t *testing.T) { }, want: want{ obj: &T{}, - err: errors.New("invalid timeout value: 5ss\t:timeout parse error out put failed: time: unknown unit \"ss\" in duration \"5ss\""), + err: errors.Join(errors.New("time: unknown unit \"ss\" in duration \"5ss\""), errors.ErrTimeoutParseFailed("5ss")), }, }, } @@ -647,7 +647,7 @@ func TestWithInitialDelayMaxDuration(t *testing.T) { }, want: want{ obj: &T{}, - err: errors.New("invalid timeout value: 5ss\t:timeout parse error out put failed: time: unknown unit \"ss\" in duration \"5ss\""), + err: errors.Join(errors.New("time: unknown unit \"ss\" in duration \"5ss\""), errors.ErrTimeoutParseFailed("5ss")), }, }, } @@ -732,7 +732,7 @@ func TestWithMinLoadIndexTimeout(t *testing.T) { }, want: want{ obj: &T{}, - err: errors.New("invalid timeout value: 5ss\t:timeout parse error out put failed: time: unknown unit \"ss\" in duration \"5ss\""), + err: errors.Join(errors.New("time: unknown unit \"ss\" in duration \"5ss\""), errors.ErrTimeoutParseFailed("5ss")), }, }, } @@ -817,7 +817,7 @@ func TestWithMaxLoadIndexTimeout(t *testing.T) { }, want: want{ obj: &T{}, - err: errors.New("invalid timeout value: 5ss\t:timeout parse error out put failed: time: unknown unit \"ss\" in duration \"5ss\""), + err: errors.Join(errors.New("time: unknown unit \"ss\" in duration \"5ss\""), errors.ErrTimeoutParseFailed("5ss")), }, }, } @@ -902,7 +902,7 @@ func TestWithLoadIndexTimeoutFactor(t *testing.T) { }, want: want{ obj: &T{}, - err: errors.New("invalid timeout value: 5ss\t:timeout parse error out put failed: time: unknown unit \"ss\" in duration \"5ss\""), + err: errors.Join(errors.New("time: unknown unit \"ss\" in duration \"5ss\""), errors.ErrTimeoutParseFailed("5ss")), }, }, } diff --git a/pkg/agent/internal/metadata/metadata.go b/pkg/agent/internal/metadata/metadata.go index 4ba4181afb..4c0225f98d 100644 --- a/pkg/agent/internal/metadata/metadata.go +++ b/pkg/agent/internal/metadata/metadata.go @@ -59,7 +59,7 @@ func Load(path string) (meta *Metadata, err error) { if f != nil { derr := f.Close() if derr != nil { - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } } }() @@ -81,7 +81,7 @@ func Store(path string, meta *Metadata) (err error) { if f != nil { derr := f.Close() if derr != nil { - err = errors.Wrap(err, derr.Error()) + err = errors.Join(err, derr) } } }() diff --git a/pkg/gateway/filter/handler/grpc/handler.go b/pkg/gateway/filter/handler/grpc/handler.go index 7388d82b00..1edba3227d 100644 --- a/pkg/gateway/filter/handler/grpc/handler.go +++ b/pkg/gateway/filter/handler/grpc/handler.go @@ -261,10 +261,10 @@ func (s *server) MultiSearchObject(ctx context.Context, reqs *payload.Search_Mul fmt.Sprintf(vald.MultiSearchObjectRPCName+" API object %s's search request result not found", string(query.GetObject())), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf(vald.MultiSearchObjectRPCName+" API object %s's search request result not found", - string(query.GetObject())), err, info.Get()).Error()) + string(query.GetObject())), err, info.Get())) } mu.Unlock() return nil @@ -504,10 +504,10 @@ func (s *server) MultiLinearSearchObject(ctx context.Context, reqs *payload.Sear fmt.Sprintf(vald.LinearSearchObjectRPCName+" API object %s's search request result not found", string(query.GetObject())), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf(vald.LinearSearchObjectRPCName+" API object %s's search request result not found", - string(query.GetObject())), err, info.Get()).Error()) + string(query.GetObject())), err, info.Get())) } mu.Unlock() return nil @@ -817,10 +817,10 @@ func (s *server) MultiInsertObject(ctx context.Context, reqs *payload.Insert_Mul fmt.Sprintf(vald.MultiInsertObjectRPCName+" API object id: %s's insert failed", query.GetObject().GetId()), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf(vald.MultiInsertObjectRPCName+" API object id: %s's insert failed", - query.GetObject().GetId()), err, info.Get()).Error()) + query.GetObject().GetId()), err, info.Get())) } mu.Unlock() return nil @@ -1070,10 +1070,10 @@ func (s *server) MultiUpdateObject(ctx context.Context, reqs *payload.Update_Mul fmt.Sprintf("MultiUpdateObject API object id: %s's insert failed", query.GetObject().GetId()), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiUpdateObject API object id: %s's insert failed", - query.GetObject().GetId()), err, info.Get()).Error()) + query.GetObject().GetId()), err, info.Get())) } mu.Unlock() return nil @@ -1330,10 +1330,10 @@ func (s *server) MultiUpsertObject(ctx context.Context, reqs *payload.Upsert_Mul fmt.Sprintf("MultiUpsertObject API object id: %s's insert failed", query.GetObject().GetId()), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiUpsertObject API object id: %s's insert failed", - query.GetObject().GetId()), err, info.Get()).Error()) + query.GetObject().GetId()), err, info.Get())) } mu.Unlock() return nil @@ -1754,10 +1754,10 @@ func (s *server) MultiSearch(ctx context.Context, reqs *payload.Search_MultiRequ fmt.Sprintf("MultiSearch API vector %v's search request result not found", query.GetVector()), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiSearch API vector %v's search request result not found", - query.GetVector()), err, info.Get()).Error()) + query.GetVector()), err, info.Get())) } mu.Unlock() return nil @@ -1824,10 +1824,10 @@ func (s *server) MultiSearchByID(ctx context.Context, reqs *payload.Search_Multi fmt.Sprintf("MultiSearchByID API id %s's search request result not found", query.GetId()), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiSearchByID API id %s's search request result not found", - query.GetId()), err, info.Get()).Error()) + query.GetId()), err, info.Get())) } mu.Unlock() return nil @@ -2223,10 +2223,10 @@ func (s *server) MultiLinearSearch(ctx context.Context, reqs *payload.Search_Mul fmt.Sprintf("MultiLinearSearch API vector %v's search request result not found", query.GetVector()), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiLinearSearch API vector %v's search request result not found", - query.GetVector()), err, info.Get()).Error()) + query.GetVector()), err, info.Get())) } mu.Unlock() return nil @@ -2285,10 +2285,10 @@ func (s *server) MultiLinearSearchByID(ctx context.Context, reqs *payload.Search fmt.Sprintf("MultiLinearSearchByID API id %s's search request result not found", query.GetId()), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiLinearSearchByID API id %s's search request result not found", - query.GetId()), err, info.Get()).Error()) + query.GetId()), err, info.Get())) } mu.Unlock() return nil @@ -2561,10 +2561,10 @@ func (s *server) MultiInsert(ctx context.Context, reqs *payload.Insert_MultiRequ fmt.Sprintf("MultiInsert API request %#v's Insert request result not found", query), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiInsert API request %#v's Insert request result not found", - query), err, info.Get()).Error()) + query), err, info.Get())) } mu.Unlock() return nil @@ -2816,10 +2816,10 @@ func (s *server) MultiUpdate(ctx context.Context, reqs *payload.Update_MultiRequ fmt.Sprintf("MultiUpdate API request %#v's Update request result not found", query), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiUpdate API request %#v's Update request result not found", - query), err, info.Get()).Error()) + query), err, info.Get())) } mu.Unlock() return nil @@ -3072,10 +3072,10 @@ func (s *server) MultiUpsert(ctx context.Context, reqs *payload.Upsert_MultiRequ fmt.Sprintf("MultiUpsert API request %#v's Upsert request result not found", query), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiUpsert API request %#v's Upsert request result not found", - query), err, info.Get()).Error()) + query), err, info.Get())) } mu.Unlock() return nil @@ -3203,10 +3203,10 @@ func (s *server) MultiRemove(ctx context.Context, reqs *payload.Remove_MultiRequ fmt.Sprintf("MultiRemove API id %s's Remove request result not found", query.GetId()), err, info.Get()) } else { - errs = errors.Wrap(errs, + errs = errors.Join(errs, status.WrapWithNotFound( fmt.Sprintf("MultiRemove API id %s's Remove request result not found", - query.GetId()), err, info.Get()).Error()) + query.GetId()), err, info.Get())) } mu.Unlock() return nil diff --git a/pkg/gateway/filter/usecase/vald.go b/pkg/gateway/filter/usecase/vald.go index 2cb44e64cf..447671b99b 100644 --- a/pkg/gateway/filter/usecase/vald.go +++ b/pkg/gateway/filter/usecase/vald.go @@ -292,12 +292,12 @@ func (r *run) Stop(ctx context.Context) error { func (r *run) PostStop(ctx context.Context) (err error) { defer func() { if err != nil { - err = errors.Wrap(r.ingress.Stop(ctx), errors.Wrap(r.egress.Stop(ctx), err.Error()).Error()) + err = errors.Join(r.ingress.Stop(ctx), errors.Join(r.egress.Stop(ctx), err)) return } err = r.ingress.Stop(ctx) if err != nil { - err = errors.Wrap(r.egress.Stop(ctx), err.Error()) + err = errors.Join(r.egress.Stop(ctx), err) return } err = r.egress.Stop(ctx) diff --git a/pkg/manager/index/service/indexer.go b/pkg/manager/index/service/indexer.go index e4f01bc17d..2251c85cfe 100644 --- a/pkg/manager/index/service/indexer.go +++ b/pkg/manager/index/service/indexer.go @@ -221,7 +221,7 @@ func (idx *index) execute(ctx context.Context, enableLowIndexSkip, immediateSavi if err != nil { st, ok := status.FromError(err) if ok && st != nil && st.Code() == codes.FailedPrecondition { - log.Debugf("CreateIndex of %s skipped, message: %s, err: %v", addr, st.Message(), errors.Wrap(st.Err(), err.Error())) + log.Debugf("CreateIndex of %s skipped, message: %s, err: %v", addr, st.Message(), errors.Join(st.Err(), err)) return nil } log.Warnf("an error occurred while calling CreateIndex of %s: %s", addr, err) @@ -241,7 +241,7 @@ func (idx *index) execute(ctx context.Context, enableLowIndexSkip, immediateSavi if err != nil { st, ok := status.FromError(err) if ok && st != nil && st.Code() == codes.FailedPrecondition { - log.Debugf("CreateIndex of %s skipped, message: %s, err: %v", addr, st.Message(), errors.Wrap(st.Err(), err.Error())) + log.Debugf("CreateIndex of %s skipped, message: %s, err: %v", addr, st.Message(), errors.Join(st.Err(), err)) return nil } log.Warnf("an error occurred while calling CreateAndSaveIndex of %s: %s", addr, err) diff --git a/pkg/tools/cli/loadtest/service/loader.go b/pkg/tools/cli/loadtest/service/loader.go index 07d69d0adc..216aa72a47 100644 --- a/pkg/tools/cli/loadtest/service/loader.go +++ b/pkg/tools/cli/loadtest/service/loader.go @@ -114,7 +114,7 @@ func (l *loader) Do(ctx context.Context) <-chan error { finalize := func(ctx context.Context, err error) { select { case <-ctx.Done(): - ech <- errors.Wrap(err, ctx.Err().Error()) + ech <- errors.Join(err, ctx.Err()) case ech <- err: } } diff --git a/pkg/tools/cli/loadtest/usecase/load.go b/pkg/tools/cli/loadtest/usecase/load.go index 5383772c06..dc67c02c0d 100644 --- a/pkg/tools/cli/loadtest/usecase/load.go +++ b/pkg/tools/cli/loadtest/usecase/load.go @@ -90,12 +90,12 @@ func (r *run) Start(ctx context.Context) (<-chan error, error) { if r.client != nil { err = r.client.Close(ctx) if err != nil { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } } err = ctx.Err() if err != nil && !errors.Is(err, context.Canceled) { - errs = errors.Wrap(errs, err.Error()) + errs = errors.Join(errs, err) } return errs } diff --git a/tests/e2e/operation/stream.go b/tests/e2e/operation/stream.go index da24b4e5e5..33071f6076 100644 --- a/tests/e2e/operation/stream.go +++ b/tests/e2e/operation/stream.go @@ -114,12 +114,12 @@ func (c *client) SearchWithParameters( if err != nil { if err := evalidator(t, err); err != nil { - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) } return @@ -134,7 +134,7 @@ func (c *client) SearchWithParameters( status.GetCode(), status.GetMessage(), errdetails.Serialize(status.GetDetails())) - rerr = errors.Wrap(rerr, e.Error()) + rerr = errors.Join(rerr, e) } continue } @@ -238,12 +238,12 @@ func (c *client) SearchByIDWithParameters( if err != nil { if err := evalidator(t, err); err != nil { - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) } return @@ -258,7 +258,7 @@ func (c *client) SearchByIDWithParameters( status.GetCode(), status.GetMessage(), errdetails.Serialize(status.GetDetails())) - rerr = errors.Wrap(rerr, e.Error()) + rerr = errors.Join(rerr, e) } continue } @@ -349,12 +349,12 @@ func (c *client) LinearSearchWithParameters( if err != nil { if err := evalidator(t, err); err != nil { - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) } return @@ -369,7 +369,7 @@ func (c *client) LinearSearchWithParameters( status.GetCode(), status.GetMessage(), errdetails.Serialize(status.GetDetails())) - rerr = errors.Wrap(rerr, e.Error()) + rerr = errors.Join(rerr, e) } continue } @@ -467,12 +467,12 @@ func (c *client) LinearSearchByIDWithParameters( if err != nil { if err := evalidator(t, err); err != nil { - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) } return @@ -487,7 +487,7 @@ func (c *client) LinearSearchByIDWithParameters( status.GetCode(), status.GetMessage(), errdetails.Serialize(status.GetDetails())) - rerr = errors.Wrap(rerr, e.Error()) + rerr = errors.Join(rerr, e) } continue } @@ -573,12 +573,12 @@ func (c *client) InsertWithParameters( if err != nil { if err := evalidator(t, err); err != nil { - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) } return @@ -593,7 +593,7 @@ func (c *client) InsertWithParameters( status.GetCode(), status.GetMessage(), errdetails.Serialize(status.GetDetails())) - rerr = errors.Wrap(rerr, e.Error()) + rerr = errors.Join(rerr, e) } continue } @@ -676,12 +676,12 @@ func (c *client) UpdateWithParameters( if err != nil { if err := evalidator(t, err); err != nil { - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) } return @@ -696,7 +696,7 @@ func (c *client) UpdateWithParameters( status.GetCode(), status.GetMessage(), errdetails.Serialize(status.GetDetails())) - rerr = errors.Wrap(rerr, e.Error()) + rerr = errors.Join(rerr, e) } continue } @@ -780,12 +780,12 @@ func (c *client) UpsertWithParameters( if err != nil { if err := evalidator(t, err); err != nil { - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) } return @@ -800,7 +800,7 @@ func (c *client) UpsertWithParameters( status.GetCode(), status.GetMessage(), errdetails.Serialize(status.GetDetails())) - rerr = errors.Wrap(rerr, e.Error()) + rerr = errors.Join(rerr, e) } continue } @@ -882,12 +882,12 @@ func (c *client) RemoveWithParameters( if err != nil { if err := evalidator(t, err); err != nil { - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) } return @@ -902,7 +902,7 @@ func (c *client) RemoveWithParameters( status.GetCode(), status.GetMessage(), errdetails.Serialize(status.GetDetails())) - rerr = errors.Wrap(rerr, e.Error()) + rerr = errors.Join(rerr, e) } continue } @@ -991,12 +991,12 @@ func (c *client) GetObject( if err != nil { err = ParseAndLogError(t, err) - rerr = errors.Wrap( + rerr = errors.Join( rerr, errors.Errorf( "stream finished by an error: %s", err.Error(), - ).Error(), + ), ) return }