summaryrefslogtreecommitdiff
path: root/vendor/k8s.io/apimachinery/pkg/util/errors/errors.go
diff options
context:
space:
mode:
authordependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>2020-05-05 08:57:17 +0000
committerDaniel J Walsh <dwalsh@redhat.com>2020-05-05 13:35:55 -0400
commit2f0bc5ff1cde9afb595868b92dd123478af9ef74 (patch)
treed620dce86657a325eb82b251f95e9cd4903ca80f /vendor/k8s.io/apimachinery/pkg/util/errors/errors.go
parente1be837a4ff149e00ff6af9e71cf9ea625e33e6f (diff)
downloadpodman-2f0bc5ff1cde9afb595868b92dd123478af9ef74.tar.gz
podman-2f0bc5ff1cde9afb595868b92dd123478af9ef74.tar.bz2
podman-2f0bc5ff1cde9afb595868b92dd123478af9ef74.zip
Bump k8s.io/api from 0.17.4 to 0.18.2
Bumps [k8s.io/api](https://github.com/kubernetes/api) from 0.17.4 to 0.18.2. - [Release notes](https://github.com/kubernetes/api/releases) - [Commits](https://github.com/kubernetes/api/compare/v0.17.4...v0.18.2) Signed-off-by: dependabot-preview[bot] <support@dependabot.com> Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/k8s.io/apimachinery/pkg/util/errors/errors.go')
-rw-r--r--vendor/k8s.io/apimachinery/pkg/util/errors/errors.go32
1 files changed, 26 insertions, 6 deletions
diff --git a/vendor/k8s.io/apimachinery/pkg/util/errors/errors.go b/vendor/k8s.io/apimachinery/pkg/util/errors/errors.go
index 62a73f34e..5bafc218e 100644
--- a/vendor/k8s.io/apimachinery/pkg/util/errors/errors.go
+++ b/vendor/k8s.io/apimachinery/pkg/util/errors/errors.go
@@ -28,9 +28,14 @@ type MessageCountMap map[string]int
// Aggregate represents an object that contains multiple errors, but does not
// necessarily have singular semantic meaning.
+// The aggregate can be used with `errors.Is()` to check for the occurrence of
+// a specific error type.
+// Errors.As() is not supported, because the caller presumably cares about a
+// specific error of potentially multiple that match the given type.
type Aggregate interface {
error
Errors() []error
+ Is(error) bool
}
// NewAggregate converts a slice of errors into an Aggregate interface, which
@@ -71,16 +76,17 @@ func (agg aggregate) Error() string {
}
seenerrs := sets.NewString()
result := ""
- agg.visit(func(err error) {
+ agg.visit(func(err error) bool {
msg := err.Error()
if seenerrs.Has(msg) {
- return
+ return false
}
seenerrs.Insert(msg)
if len(seenerrs) > 1 {
result += ", "
}
result += msg
+ return false
})
if len(seenerrs) == 1 {
return result
@@ -88,19 +94,33 @@ func (agg aggregate) Error() string {
return "[" + result + "]"
}
-func (agg aggregate) visit(f func(err error)) {
+func (agg aggregate) Is(target error) bool {
+ return agg.visit(func(err error) bool {
+ return errors.Is(err, target)
+ })
+}
+
+func (agg aggregate) visit(f func(err error) bool) bool {
for _, err := range agg {
switch err := err.(type) {
case aggregate:
- err.visit(f)
+ if match := err.visit(f); match {
+ return match
+ }
case Aggregate:
for _, nestedErr := range err.Errors() {
- f(nestedErr)
+ if match := f(nestedErr); match {
+ return match
+ }
}
default:
- f(err)
+ if match := f(err); match {
+ return match
+ }
}
}
+
+ return false
}
// Errors is part of the Aggregate interface.