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. // IsErrKeyExist returns true if it is ErrKeyExist.
func IsErrKeyExist(err error) bool { func IsErrKeyExist(err error) bool {
_, ok := errors.Cause(err).(*ErrKeyExist) var e *ErrKeyExist
return ok return errors.As(err, &e)
} }
// ErrWriteConflict wraps *kvrpcpb.ErrWriteConflict to implement the error interface. // 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. // IsErrWriteConflict returns true if it is ErrWriteConflict.
func IsErrWriteConflict(err error) bool { func IsErrWriteConflict(err error) bool {
_, ok := errors.Cause(err).(*ErrWriteConflict) var e *ErrWriteConflict
return ok return errors.As(err, &e)
} }
//NewErrWriteConfictWithArgs generates an ErrWriteConflict with args. //NewErrWriteConfictWithArgs generates an ErrWriteConflict with args.