diff --git a/markers/markers.go b/markers/markers.go index fa69b0c..3f81794 100644 --- a/markers/markers.go +++ b/markers/markers.go @@ -179,6 +179,13 @@ func IsAny(err error, references ...error) bool { return true } } + + // Recursively try multi-error causes, if applicable. + for _, me := range errbase.UnwrapMulti(c) { + if IsAny(me, references...) { + return true + } + } } // Try harder with marks. diff --git a/markers/markers_test.go b/markers/markers_test.go index 72dec03..b9cdcf1 100644 --- a/markers/markers_test.go +++ b/markers/markers_test.go @@ -361,6 +361,10 @@ func TestIsAny(t *testing.T) { err2 := errors.New("world") err3 := pkgErr.Wrap(err1, "world") err4 := pkgErr.Wrap(err2, "universe") + err5 := errors.Join(err1, errors.New("gopher")) + err6 := errors.Join(errors.New("gopher"), err2) + err7 := errors.Join(err1, err2) + err8 := pkgErr.Wrap(err7, "gopher") var nilErr error tt.Check(markers.IsAny(err1, err1)) @@ -371,6 +375,14 @@ func TestIsAny(t *testing.T) { tt.Check(markers.IsAny(err3, err2, nilErr, err1)) tt.Check(markers.IsAny(nilErr, err2, nilErr, err1)) tt.Check(!markers.IsAny(nilErr, err2, err1)) + tt.Check(markers.IsAny(err5, err1)) + tt.Check(markers.IsAny(err6, err2)) + tt.Check(markers.IsAny(err7, err1)) + tt.Check(markers.IsAny(err7, err2)) + tt.Check(markers.IsAny(err7, err1, err2)) + tt.Check(markers.IsAny(err8, err1)) + tt.Check(markers.IsAny(err8, err2)) + tt.Check(markers.IsAny(err8, err1, err2)) } // This test demonstrates that two errors that are structurally