v0.0.510
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 4m24s

This commit is contained in:
2024-09-13 18:06:49 +02:00
parent 3a17edfaf0
commit a1668b6e5a
5 changed files with 56 additions and 11 deletions

View File

@@ -12,6 +12,8 @@ import (
var reflectTypeStr = reflect.TypeOf("")
func FromError(err error) *ExErr {
//goland:noinspection GoTypeAssertionOnErrors
if verr, ok := err.(*ExErr); ok {
// A simple ExErr
return verr

View File

@@ -86,3 +86,28 @@ func MessageMatch(e error, matcher func(string) bool) bool {
return false
}
// OriginalError returns the lowest level error, probably the original/external error that was originally wrapped
func OriginalError(e error) error {
if e == nil {
return nil
}
//goland:noinspection GoTypeAssertionOnErrors
bmerr, ok := e.(*ExErr)
for !ok {
return e
}
for bmerr.OriginalError != nil {
bmerr = bmerr.OriginalError
}
if bmerr.WrappedErr != nil {
if werr, ok := bmerr.WrappedErr.(error); ok {
return werr
}
}
return bmerr
}