From 5aba05d7237c2250e647a717f8abef658f30a9e9 Mon Sep 17 00:00:00 2001 From: Keuin Date: Sat, 1 Jul 2023 22:02:01 +0800 Subject: Refactor: replace homemade error type checking with idiom Go practices. --- common/errors.go | 25 ------------------------- 1 file changed, 25 deletions(-) (limited to 'common/errors.go') diff --git a/common/errors.go b/common/errors.go index 62899c1..bdf49fb 100644 --- a/common/errors.go +++ b/common/errors.go @@ -1,34 +1,9 @@ package common import ( - "errors" "fmt" - "reflect" ) -// IsErrorOfType is a modified version of errors.Is, which loosen the check condition -func IsErrorOfType(err, target error) bool { - if target == nil { - return err == target - } - - isComparable := reflect.TypeOf(target).Comparable() - for { - if isComparable && reflect.TypeOf(target) == reflect.TypeOf(err) { - return true - } - if x, ok := err.(interface{ Is(error) bool }); ok && x.Is(target) { - return true - } - // TODO: consider supporting target.Is(err). This would allow - // user-definable predicates, but also may allow for coping with sloppy - // APIs, thereby making it easier to get away with them. - if err = errors.Unwrap(err); err == nil { - return false - } - } -} - /* Task errors. */ -- cgit v1.2.3