mirror of
https://github.com/kubernetes/client-go.git
synced 2025-08-11 12:11:52 +00:00
Embed context deadline exceeded in error to let errors.Is can work
Currently, watch package embeds context deadlineexceeded error in it's own error using `%v`, as can be seen in here; `fmt.Errorf("UntilWithSync: unable to sync caches: %v", ctx.Err())` However, consumers of this function can not use `errors.Is(err, context.DeadlineExceeded)` due this `%v`. To let consumers can distinguish context deadlineexceeded errors, this PR changes error embedding format to `%w`. Kubernetes-commit: 6b7c365f8f6d50280c2dab171efdd4b93d964f32
This commit is contained in:
parent
19c9966172
commit
21fffc1153
@ -136,7 +136,7 @@ func UntilWithSync(ctx context.Context, lw cache.ListerWatcher, objType runtime.
|
||||
|
||||
if precondition != nil {
|
||||
if !cache.WaitForCacheSync(ctx.Done(), informer.HasSynced) {
|
||||
return nil, fmt.Errorf("UntilWithSync: unable to sync caches: %v", ctx.Err())
|
||||
return nil, fmt.Errorf("UntilWithSync: unable to sync caches: %w", ctx.Err())
|
||||
}
|
||||
|
||||
done, err := precondition(indexer)
|
||||
|
@ -19,6 +19,7 @@ package watch
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
@ -227,7 +228,7 @@ func TestUntilWithSync(t *testing.T) {
|
||||
conditionFunc: func(e watch.Event) (bool, error) {
|
||||
return true, nil
|
||||
},
|
||||
expectedErr: errors.New("UntilWithSync: unable to sync caches: context deadline exceeded"),
|
||||
expectedErr: fmt.Errorf("UntilWithSync: unable to sync caches: %w", context.DeadlineExceeded),
|
||||
expectedEvent: nil,
|
||||
},
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user