mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-12-22 19:33:32 +02:00
Refactor to stdlib error unwrap method
This commit is contained in:
parent
f1d753f069
commit
c4a307e84d
2 changed files with 8 additions and 19 deletions
|
@ -48,7 +48,7 @@ func (e readError) Error() string {
|
|||
return e.error.Error()
|
||||
}
|
||||
|
||||
func (e readError) Inner() error {
|
||||
func (e readError) Unwrap() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,7 @@ func (e writeError) Error() string {
|
|||
return e.error.Error()
|
||||
}
|
||||
|
||||
func (e writeError) Inner() error {
|
||||
func (e writeError) Unwrap() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
package errors // import "github.com/xtls/xray-core/common/errors"
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
|
@ -13,8 +12,8 @@ import (
|
|||
const trim = len("github.com/xtls/xray-core/")
|
||||
|
||||
type hasInnerError interface {
|
||||
// Inner returns the underlying error of this one.
|
||||
Inner() error
|
||||
// Unwrap returns the underlying error of this one.
|
||||
Unwrap() error
|
||||
}
|
||||
|
||||
type hasSeverity interface {
|
||||
|
@ -72,8 +71,8 @@ func (err *Error) Error() string {
|
|||
return builder.String()
|
||||
}
|
||||
|
||||
// Inner implements hasInnerError.Inner()
|
||||
func (err *Error) Inner() error {
|
||||
// Unwrap implements hasInnerError.Unwrap()
|
||||
func (err *Error) Unwrap() error {
|
||||
if err.inner == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -171,20 +170,10 @@ L:
|
|||
for {
|
||||
switch inner := err.(type) {
|
||||
case hasInnerError:
|
||||
if inner.Inner() == nil {
|
||||
if inner.Unwrap() == nil {
|
||||
break L
|
||||
}
|
||||
err = inner.Inner()
|
||||
case *os.PathError:
|
||||
if inner.Err == nil {
|
||||
break L
|
||||
}
|
||||
err = inner.Err
|
||||
case *os.SyscallError:
|
||||
if inner.Err == nil {
|
||||
break L
|
||||
}
|
||||
err = inner.Err
|
||||
err = inner.Unwrap()
|
||||
default:
|
||||
break L
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue