Skip to content

Commit aa7d254

Browse files
committed
Fix errors usage
1 parent 33beacc commit aa7d254

File tree

3 files changed

+9
-28
lines changed

3 files changed

+9
-28
lines changed

common/baderror/baderror.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ package baderror
22

33
import (
44
"context"
5+
"errors"
56
"io"
67
"net"
78
"strings"
8-
9-
E "github.com/sagernet/sing/common/exceptions"
109
)
1110

1211
func Contains(err error, msgList ...string) bool {
@@ -22,8 +21,7 @@ func WrapH2(err error) error {
2221
if err == nil {
2322
return nil
2423
}
25-
err = E.Unwrap(err)
26-
if err == io.ErrUnexpectedEOF {
24+
if errors.Is(err, io.ErrUnexpectedEOF) {
2725
return io.EOF
2826
}
2927
if Contains(err, "client disconnected", "body closed by handler", "response body closed", "; CANCEL") {

common/exceptions/inner.go

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,14 @@
11
package exceptions
22

3-
import "github.com/sagernet/sing/common"
3+
import (
4+
"errors"
45

5-
type HasInnerError interface {
6-
Unwrap() error
7-
}
6+
"github.com/sagernet/sing/common"
7+
)
88

9+
// Deprecated: Use errors.Unwrap instead.
910
func Unwrap(err error) error {
10-
for {
11-
inner, ok := err.(HasInnerError)
12-
if !ok {
13-
break
14-
}
15-
innerErr := inner.Unwrap()
16-
if innerErr == nil {
17-
break
18-
}
19-
err = innerErr
20-
}
21-
return err
11+
return errors.Unwrap(err)
2212
}
2313

2414
func Cast[T any](err error) (T, bool) {

common/exceptions/multi.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,5 @@ func IsMulti(err error, targetList ...error) bool {
6363
return true
6464
}
6565
}
66-
err = Unwrap(err)
67-
multiErr, isMulti := err.(MultiError)
68-
if !isMulti {
69-
return false
70-
}
71-
return common.All(multiErr.Unwrap(), func(it error) bool {
72-
return IsMulti(it, targetList...)
73-
})
66+
return false
7467
}

0 commit comments

Comments
 (0)