-
Notifications
You must be signed in to change notification settings - Fork 47
Description
Hello,
There seems to be a correctness issue the implementation of multiError.Is. I say "seems" because I cannot find any consensus on what errors.Is(err, ErrIgnorable) should actually be doing when err is a multiError containing both ErrIgnorable and an important error (that you do want to handle).
Perhaps Is should only return true if all contained errors match the target, so instead
func (merr *multiError) Is(target error) bool {
if len(merr.Errors()) == 0 {
return false
}
for _, err := range merr.Errors() {
if !errors.Is(err, target) {
return false
}
}
return true
}
an alternative would be that Is is not implemented at all, and then errors.Is should return false.
Again, I don't know if the golang developers ever specified some semantics for errors.Is, but I think that from both an intuitive and practical sense, errors.Is(err, ErrIgnorable) should return false. Intuitive, because a multiError is not equal to a single error, and practical because if the important error is not represented by a value, e.g. val ErrImportant = errors.New(...), then there is no way to easily ignore only ignorable error without calling Errors() and iterating over the individual errors..