From aa7d2543a3ce2b3a639c6bf8cb8f241159f4c487 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sat, 14 Dec 2024 18:16:15 +0800 Subject: [PATCH] Fix errors usage --- common/baderror/baderror.go | 6 ++---- common/exceptions/inner.go | 22 ++++++---------------- common/exceptions/multi.go | 9 +-------- 3 files changed, 9 insertions(+), 28 deletions(-) diff --git a/common/baderror/baderror.go b/common/baderror/baderror.go index c5ab530a..d90ddeb2 100644 --- a/common/baderror/baderror.go +++ b/common/baderror/baderror.go @@ -2,11 +2,10 @@ package baderror import ( "context" + "errors" "io" "net" "strings" - - E "github.com/sagernet/sing/common/exceptions" ) func Contains(err error, msgList ...string) bool { @@ -22,8 +21,7 @@ func WrapH2(err error) error { if err == nil { return nil } - err = E.Unwrap(err) - if err == io.ErrUnexpectedEOF { + if errors.Is(err, io.ErrUnexpectedEOF) { return io.EOF } if Contains(err, "client disconnected", "body closed by handler", "response body closed", "; CANCEL") { diff --git a/common/exceptions/inner.go b/common/exceptions/inner.go index 3799af9b..58bcc5ac 100644 --- a/common/exceptions/inner.go +++ b/common/exceptions/inner.go @@ -1,24 +1,14 @@ package exceptions -import "github.com/sagernet/sing/common" +import ( + "errors" -type HasInnerError interface { - Unwrap() error -} + "github.com/sagernet/sing/common" +) +// Deprecated: Use errors.Unwrap instead. func Unwrap(err error) error { - for { - inner, ok := err.(HasInnerError) - if !ok { - break - } - innerErr := inner.Unwrap() - if innerErr == nil { - break - } - err = innerErr - } - return err + return errors.Unwrap(err) } func Cast[T any](err error) (T, bool) { diff --git a/common/exceptions/multi.go b/common/exceptions/multi.go index 2cdec05b..78fb3b6f 100644 --- a/common/exceptions/multi.go +++ b/common/exceptions/multi.go @@ -63,12 +63,5 @@ func IsMulti(err error, targetList ...error) bool { return true } } - err = Unwrap(err) - multiErr, isMulti := err.(MultiError) - if !isMulti { - return false - } - return common.All(multiErr.Unwrap(), func(it error) bool { - return IsMulti(it, targetList...) - }) + return false }