Merge pull request #460 from grafana/implement-multi-errors-is

Implement Is() for multierrors
This commit is contained in:
Oleg Zaytsev 2023-03-22 17:55:37 +01:00 committed by GitHub
commit f7f1fc750c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,7 @@ package errors
import (
"bytes"
"errors"
"fmt"
"io"
)
@ -79,6 +80,19 @@ func (es nonNilMultiError) Error() string {
return buf.String()
}
// Is attempts to match the provided error against errors in the error list.
//
// This function allows errors.Is to traverse the values stored in the MultiError.
// It returns true if any of the errors in the list match the target.
func (es nonNilMultiError) Is(target error) bool {
for _, err := range es.errs {
if errors.Is(err, target) {
return true
}
}
return false
}
// CloseAll closes all given closers while recording error in MultiError.
func CloseAll(cs []io.Closer) error {
errs := NewMulti()