Skip to content

Commit

Permalink
[patch] bugfix error assertion (#680)
Browse files Browse the repository at this point in the history
* [patch] bugfix error assertion

Signed-off-by: kpango <[email protected]>

* fix

Signed-off-by: kpango <[email protected]>
  • Loading branch information
Yusuke Kato authored Sep 8, 2020
2 parents 59df91e + d7d999b commit e3e2d63
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 19 deletions.
11 changes: 10 additions & 1 deletion internal/db/rdb/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions internal/errors/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
6 changes: 4 additions & 2 deletions internal/errors/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
6 changes: 4 additions & 2 deletions internal/errors/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}
3 changes: 2 additions & 1 deletion internal/errors/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
6 changes: 2 additions & 4 deletions pkg/meta/cassandra/service/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
37 changes: 30 additions & 7 deletions pkg/meta/redis/service/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit e3e2d63

Please sign in to comment.