Skip to content

Commit

Permalink
Use suggested unwrapAll
Browse files Browse the repository at this point in the history
  • Loading branch information
craig65535 committed Dec 31, 2024
1 parent 95dafb4 commit 5e478a1
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions assert/assertions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2171,23 +2171,22 @@ func NotErrorAs(t TestingT, err error, target interface{}, msgAndArgs ...interfa

func unwrapAll(err error) (errs []error) {
errs = append(errs, err)
for {
switch x := err.(type) {
case interface{ Unwrap() error }:
err = x.Unwrap()
if err == nil {
return
}
errs = append(errs, err)
case interface{ Unwrap() []error }:
for _, err := range x.Unwrap() {
errs = append(errs, unwrapAll(err)...)
}
return
default:
switch x := err.(type) {
case interface{ Unwrap() error }:
err = x.Unwrap()
if err == nil {
return
}
errs = append(errs, unwrapAll(err)...)
case interface{ Unwrap() []error }:
for _, err := range x.Unwrap() {
errs = append(errs, unwrapAll(err)...)
}
return
default:
return
}
return
}

func buildErrorChainString(err error, withType bool) string {
Expand Down

0 comments on commit 5e478a1

Please sign in to comment.