mirror of
https://github.com/nabbar/golib.git
synced 2025-10-04 07:26:39 +08:00
Package Errors: fix compatiblity with GOROOT errors packages + fix recursive HasCode function
This commit is contained in:
@@ -133,7 +133,7 @@ func (e *ers) HasCode(code CodeError) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range e.p {
|
for _, p := range e.p {
|
||||||
if p.IsCode(code) {
|
if p.HasCode(code) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -285,6 +285,31 @@ func (e *ers) GetErrorSlice() []error {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (e *ers) Unwrap() []error {
|
||||||
|
var r = []error{
|
||||||
|
&ers{
|
||||||
|
c: e.c,
|
||||||
|
e: e.e,
|
||||||
|
p: nil,
|
||||||
|
t: e.t,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(e.p) < 1 {
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, v := range e.p {
|
||||||
|
if v == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
r = append(r, v.Unwrap()...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
func (e *ers) GetTrace() string {
|
func (e *ers) GetTrace() string {
|
||||||
if e.t.File != "" {
|
if e.t.File != "" {
|
||||||
return fmt.Sprintf("%s#%d", filterPath(e.t.File), e.t.Line)
|
return fmt.Sprintf("%s#%d", filterPath(e.t.File), e.t.Line)
|
||||||
|
@@ -95,6 +95,8 @@ type Error interface {
|
|||||||
GetError() error
|
GetError() error
|
||||||
//GetErrorSlice is used to return a slice of new error interface, based of the current error and all parent
|
//GetErrorSlice is used to return a slice of new error interface, based of the current error and all parent
|
||||||
GetErrorSlice() []error
|
GetErrorSlice() []error
|
||||||
|
//Unwrap will set compliance with errors As/Is functions
|
||||||
|
Unwrap() []error
|
||||||
|
|
||||||
//GetTrace will return a comped string for the trace of the current Error
|
//GetTrace will return a comped string for the trace of the current Error
|
||||||
GetTrace() string
|
GetTrace() string
|
||||||
@@ -137,7 +139,6 @@ func Is(e error) bool {
|
|||||||
|
|
||||||
func Get(e error) Error {
|
func Get(e error) Error {
|
||||||
var err Error
|
var err Error
|
||||||
|
|
||||||
if errors.As(e, &err) {
|
if errors.As(e, &err) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user