errors: use As to check error type (#361)

This commit is contained in:
disksing 2021-11-01 18:32:00 +08:00 committed by GitHub
parent 5a13df80a6
commit c0efee0618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -131,8 +131,8 @@ func (k *ErrKeyExist) Error() string {
// IsErrKeyExist returns true if it is ErrKeyExist.
func IsErrKeyExist(err error) bool {
_, ok := errors.Cause(err).(*ErrKeyExist)
return ok
var e *ErrKeyExist
return errors.As(err, &e)
}
// ErrWriteConflict wraps *kvrpcpb.ErrWriteConflict to implement the error interface.
@ -146,8 +146,8 @@ func (k *ErrWriteConflict) Error() string {
// IsErrWriteConflict returns true if it is ErrWriteConflict.
func IsErrWriteConflict(err error) bool {
_, ok := errors.Cause(err).(*ErrWriteConflict)
return ok
var e *ErrWriteConflict
return errors.As(err, &e)
}
//NewErrWriteConfictWithArgs generates an ErrWriteConflict with args.