Join errors feature is not avaliable at go 1.19

This commit is contained in:
Foil-hat-guy 2025-05-08 19:24:11 +03:00
parent 46d854d0e9
commit 6a88132acf
No known key found for this signature in database
GPG key ID: 221CC305A7B23591

View file

@ -1,30 +1,9 @@
package stty package stty
import( import (
"fmt" "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) { func filterNilErrors(errs []error) (notNilErrs []error) {
for _, err := range errs { for _, err := range errs {
if err != nil { if err != nil {
@ -41,16 +20,12 @@ func Join(errs ...error) (result error) {
} }
for index, err := range errs { for index, err := range errs {
fmt.Println(isUnwrapable(err), err.Error())
err = enshureUnwrapable(err)
fmt.Println(isUnwrapable(err), err.Error())
if index == 0 { if index == 0 {
result = err result = err
} else { } else {
result = fmt.Errorf("%w: %w", result, fmt.Errorf("foo")) result = fmt.Errorf("%w: %v", result, err)
fmt.Println("1: ",result)
fmt.Println("2: ",err)
} }
} }
return result return result
} }