diff --git a/internal/db/rdb/mysql/mysql.go b/internal/db/rdb/mysql/mysql.go index eed2835556..ea1c92579e 100644 --- a/internal/db/rdb/mysql/mysql.go +++ b/internal/db/rdb/mysql/mysql.go @@ -135,7 +135,16 @@ func (m *mySQLClient) Ping(ctx context.Context) (err error) { for { select { case <-pctx.Done(): - return errors.Wrap(errors.Wrap(err, errors.ErrMySQLConnectionPingFailed.Error()), ctx.Err().Error()) + if err != nil { + err = errors.Wrap(errors.ErrMySQLConnectionPingFailed, err.Error()) + } else { + err = errors.ErrMySQLConnectionPingFailed + } + cerr := ctx.Err() + if cerr != nil { + err = errors.Wrap(err, cerr.Error()) + } + return err case <-tick.C: err = m.session.PingContext(ctx) if err == nil { diff --git a/internal/errors/blob.go b/internal/errors/blob.go index 7026f6d10f..853f0b34e6 100644 --- a/internal/errors/blob.go +++ b/internal/errors/blob.go @@ -45,7 +45,8 @@ func (e *ErrBlobNoSuchBucket) Unwrap() error { } func IsErrBlobNoSuchBucket(err error) bool { - return As(err, &ErrBlobNoSuchBucket{}) + target := new(ErrBlobNoSuchBucket) + return As(err, &target) } type ErrBlobNoSuchKey struct { @@ -61,5 +62,6 @@ func (e *ErrBlobNoSuchKey) Unwrap() error { } func IsErrBlobNoSuchKey(err error) bool { - return As(err, &ErrBlobNoSuchKey{}) + target := new(ErrBlobNoSuchKey) + return As(err, &target) } diff --git a/internal/errors/cassandra.go b/internal/errors/cassandra.go index 5e7bd878a8..8e9a3f23bf 100644 --- a/internal/errors/cassandra.go +++ b/internal/errors/cassandra.go @@ -79,7 +79,8 @@ func (e *ErrCassandraNotFoundIdentity) Unwrap() error { } func IsErrCassandraNotFound(err error) bool { - return As(err, &ErrCassandraNotFoundIdentity{}) + target := new(ErrCassandraNotFoundIdentity) + return As(err, &target) } type ErrCassandraUnavailableIdentity struct { @@ -95,5 +96,6 @@ func (e *ErrCassandraUnavailableIdentity) Unwrap() error { } func IsErrCassandraUnavailable(err error) bool { - return As(err, &ErrCassandraUnavailableIdentity{}) + target := new(ErrCassandraUnavailableIdentity) + return As(err, &target) } diff --git a/internal/errors/mysql.go b/internal/errors/mysql.go index 78d674a583..82d2c85e27 100644 --- a/internal/errors/mysql.go +++ b/internal/errors/mysql.go @@ -57,7 +57,8 @@ func (e *ErrMySQLNotFoundIdentity) Unwrap() error { } func IsErrMySQLNotFound(err error) bool { - return As(err, &ErrMySQLNotFoundIdentity{}) + target := new(ErrMySQLNotFoundIdentity) + return As(err, &target) } type ErrMySQLInvalidArgumentIdentity struct { @@ -73,5 +74,6 @@ func (e *ErrMySQLInvalidArgumentIdentity) Unwrap() error { } func IsErrMySQLInvalidArgument(err error) bool { - return As(err, &ErrMySQLInvalidArgumentIdentity{}) + target := new(ErrMySQLInvalidArgumentIdentity) + return As(err, &target) } diff --git a/internal/errors/redis.go b/internal/errors/redis.go index 1226c10d5b..ad2caf7e2e 100644 --- a/internal/errors/redis.go +++ b/internal/errors/redis.go @@ -68,5 +68,6 @@ func (e *ErrRedisNotFoundIdentity) Unwrap() error { } func IsErrRedisNotFound(err error) bool { - return As(err, &ErrRedisNotFoundIdentity{}) + target := new(ErrRedisNotFoundIdentity) + return As(err, &target) } diff --git a/pkg/meta/cassandra/service/cassandra.go b/pkg/meta/cassandra/service/cassandra.go index b84ad86008..ea28a27799 100644 --- a/pkg/meta/cassandra/service/cassandra.go +++ b/pkg/meta/cassandra/service/cassandra.go @@ -116,8 +116,7 @@ func (c *client) GetMultiple(keys ...string) (vals []string, err error) { } vals = append(vals, "") if err != nil { - err = errors.Wrap(err, errors.ErrCassandraNotFound(key).Error()) - + err = errors.Wrap(errors.ErrCassandraNotFound(key), err.Error()) continue } err = errors.ErrCassandraNotFound(key) @@ -168,8 +167,7 @@ func (c *client) GetInverseMultiple(vals ...string) (keys []string, err error) { } keys = append(keys, "") if err != nil { - err = errors.Wrap(err, errors.ErrCassandraNotFound(val).Error()) - + err = errors.Wrap(errors.ErrCassandraNotFound(val), err.Error()) continue } err = errors.ErrCassandraNotFound(val) diff --git a/pkg/meta/redis/service/redis.go b/pkg/meta/redis/service/redis.go index 4aae14034b..10bda41c0c 100644 --- a/pkg/meta/redis/service/redis.go +++ b/pkg/meta/redis/service/redis.go @@ -132,9 +132,9 @@ func (c *client) getMulti(ctx context.Context, prefix string, keys ...string) (v err = res.Err() if err != nil { if err == redis.Nil { - err = errors.Wrap(err, errors.ErrRedisNotFound(k).Error()) + err = errors.Wrap(errors.ErrRedisNotFound(k), err.Error()) } else { - err = errors.Wrap(err, errors.ErrRedisGetOperationFailed(k, err).Error()) + err = errors.Wrap(errors.ErrRedisGetOperationFailed(k, err), err.Error()) } vals = append(vals, "") continue @@ -156,11 +156,21 @@ func (c *client) Set(ctx context.Context, key, val string) (err error) { } err = kv.Err() if err != nil { - return errors.Wrap(c.db.Del(vkKey).Err(), errors.ErrRedisSetOperationFailed(kvKey, err).Error()) + err = errors.ErrRedisSetOperationFailed(kvKey, err) + dberr := c.db.Del(vkKey).Err() + if dberr != nil { + err = errors.Wrap(err, dberr.Error()) + } + return err } err = vk.Err() if err != nil { - return errors.Wrap(c.db.Del(kvKey).Err(), errors.ErrRedisSetOperationFailed(vkKey, err).Error()) + err = errors.ErrRedisSetOperationFailed(vkKey, err) + dberr := c.db.Del(kvKey).Err() + if dberr != nil { + err = errors.Wrap(err, dberr.Error()) + } + return err } return nil } @@ -185,12 +195,20 @@ func (c *client) SetMultiple(ctx context.Context, kvs map[string]string) (err er } for vkKey, res := range kvress { if err = res.Err(); err != nil { - err = errors.Wrap(c.db.Del(vkKey).Err(), errors.ErrRedisSetOperationFailed(vks[vkKey], err).Error()) + err = errors.ErrRedisSetOperationFailed(vks[vkKey], err) + dberr := c.db.Del(vkKey).Err() + if dberr != nil { + err = errors.Wrap(err, dberr.Error()) + } } } for kvKey, res := range vkress { if err = res.Err(); err != nil { - err = errors.Wrap(c.db.Del(kvKey).Err(), errors.ErrRedisSetOperationFailed(kvs[kvKey], err).Error()) + err = errors.ErrRedisSetOperationFailed(kvs[kvKey], err) + dberr := c.db.Del(kvKey).Err() + if dberr != nil { + err = errors.Wrap(err, dberr.Error()) + } } } return err @@ -260,7 +278,12 @@ func (c *client) deleteMulti(ctx context.Context, pfx, pfxInv string, keys ...st var errs error for k, res := range ress { if err = res.Err(); err != nil { - errs = errors.Wrap(errs, errors.ErrRedisDeleteOperationFailed(k, err).Error()) + err = errors.ErrRedisDeleteOperationFailed(k, err) + if errs == nil { + errs = err + } else { + errs = errors.Wrap(err, errs.Error()) + } continue } }