Join errors feature is not avaliable at go 1.19
This commit is contained in:
parent
46d854d0e9
commit
6a88132acf
1 changed files with 4 additions and 29 deletions
33
error.go
33
error.go
|
@ -1,30 +1,9 @@
|
|||
package stty
|
||||
|
||||
import(
|
||||
"fmt"
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
type unwraperr interface {
|
||||
Unwrap() error
|
||||
}
|
||||
|
||||
type unwraperrs interface {
|
||||
Unwrap() []error
|
||||
}
|
||||
|
||||
func isUnwrapable(err error) bool {
|
||||
_, ok1 := err.(unwraperr)
|
||||
_, ok2 := err.(unwraperrs)
|
||||
return ok1 || ok2
|
||||
}
|
||||
|
||||
func enshureUnwrapable(err error) error {
|
||||
if isUnwrapable(err) {
|
||||
return fmt.Errorf(err.Error())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func filterNilErrors(errs []error) (notNilErrs []error) {
|
||||
for _, err := range errs {
|
||||
if err != nil {
|
||||
|
@ -41,16 +20,12 @@ func Join(errs ...error) (result error) {
|
|||
}
|
||||
|
||||
for index, err := range errs {
|
||||
fmt.Println(isUnwrapable(err), err.Error())
|
||||
err = enshureUnwrapable(err)
|
||||
fmt.Println(isUnwrapable(err), err.Error())
|
||||
if index == 0 {
|
||||
result = err
|
||||
} else {
|
||||
result = fmt.Errorf("%w: %w", result, fmt.Errorf("foo"))
|
||||
fmt.Println("1: ",result)
|
||||
fmt.Println("2: ",err)
|
||||
result = fmt.Errorf("%w: %v", result, err)
|
||||
}
|
||||
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue