Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
| ... | ... |
@@ -21,6 +21,7 @@ linters: |
| 21 | 21 |
- dogsled # Detects assignments with too many blank identifiers. |
| 22 | 22 |
- dupword # Detects duplicate words. |
| 23 | 23 |
- durationcheck # Detect cases where two time.Duration values are being multiplied in possibly erroneous ways. |
| 24 |
+ - errorlint # Detects code that will cause problems with the error wrapping scheme introduced in Go 1.13. |
|
| 24 | 25 |
- errchkjson # Detects unsupported types passed to json encoding functions and reports if checks for the returned error can be omitted. |
| 25 | 26 |
- exhaustive # Detects missing options in enum switch statements. |
| 26 | 27 |
- exptostd # Detects functions from golang.org/x/exp/ that can be replaced by std functions. |
| ... | ... |
@@ -75,6 +76,13 @@ linters: |
| 75 | 75 |
- "false" # some tests use this as expected output |
| 76 | 76 |
- "root" # for tests using "ls" output with files owned by "root:root" |
| 77 | 77 |
|
| 78 |
+ errorlint: |
|
| 79 |
+ # Check whether fmt.Errorf uses the %w verb for formatting errors. |
|
| 80 |
+ # See the https://github.com/polyfloyd/go-errorlint for caveats. |
|
| 81 |
+ errorf: false |
|
| 82 |
+ # Check for plain type assertions and type switches. |
|
| 83 |
+ asserts: false |
|
| 84 |
+ |
|
| 78 | 85 |
exhaustive: |
| 79 | 86 |
# Program elements to check for exhaustiveness. |
| 80 | 87 |
# Default: [ switch ] |
| ... | ... |
@@ -74,7 +74,7 @@ func ReadJSON(r *http.Request, out interface{}) error {
|
| 74 | 74 |
err = dec.Decode(out) |
| 75 | 75 |
defer r.Body.Close() |
| 76 | 76 |
if err != nil {
|
| 77 |
- if err == io.EOF {
|
|
| 77 |
+ if errors.Is(err, io.EOF) {
|
|
| 78 | 78 |
return errdefs.InvalidParameter(errors.New("invalid JSON: got EOF while reading request body"))
|
| 79 | 79 |
} |
| 80 | 80 |
return errdefs.InvalidParameter(errors.Wrap(err, "invalid JSON")) |
| ... | ... |
@@ -108,14 +108,14 @@ func (dr *distributionRouter) fetchManifest(ctx context.Context, distrepo distri |
| 108 | 108 |
} |
| 109 | 109 |
mnfst, err := mnfstsrvc.Get(ctx, distributionInspect.Descriptor.Digest) |
| 110 | 110 |
if err != nil {
|
| 111 |
- switch err {
|
|
| 112 |
- case reference.ErrReferenceInvalidFormat, |
|
| 113 |
- reference.ErrTagInvalidFormat, |
|
| 114 |
- reference.ErrDigestInvalidFormat, |
|
| 115 |
- reference.ErrNameContainsUppercase, |
|
| 116 |
- reference.ErrNameEmpty, |
|
| 117 |
- reference.ErrNameTooLong, |
|
| 118 |
- reference.ErrNameNotCanonical: |
|
| 111 |
+ switch {
|
|
| 112 |
+ case errors.Is(err, reference.ErrReferenceInvalidFormat), |
|
| 113 |
+ errors.Is(err, reference.ErrTagInvalidFormat), |
|
| 114 |
+ errors.Is(err, reference.ErrDigestInvalidFormat), |
|
| 115 |
+ errors.Is(err, reference.ErrNameContainsUppercase), |
|
| 116 |
+ errors.Is(err, reference.ErrNameEmpty), |
|
| 117 |
+ errors.Is(err, reference.ErrNameTooLong), |
|
| 118 |
+ errors.Is(err, reference.ErrNameNotCanonical): |
|
| 119 | 119 |
return registry.DistributionInspect{}, errdefs.InvalidParameter(err)
|
| 120 | 120 |
} |
| 121 | 121 |
return registry.DistributionInspect{}, err
|
| ... | ... |
@@ -96,7 +96,7 @@ func inspectResponse(ct string, r io.Reader, clen int64) (string, io.Reader, err |
| 96 | 96 |
if rlen == 0 {
|
| 97 | 97 |
return ct, r, errors.New("empty response")
|
| 98 | 98 |
} |
| 99 |
- if err != nil && err != io.EOF {
|
|
| 99 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 100 | 100 |
return ct, r, err |
| 101 | 101 |
} |
| 102 | 102 |
|
| ... | ... |
@@ -3,6 +3,7 @@ package client |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"context" |
| 6 |
+ "errors" |
|
| 6 | 7 |
"fmt" |
| 7 | 8 |
"io" |
| 8 | 9 |
"log" |
| ... | ... |
@@ -167,7 +168,7 @@ func ExampleClient_ContainerLogs_withTimeout() {
|
| 167 | 167 |
} |
| 168 | 168 |
|
| 169 | 169 |
_, err = io.Copy(os.Stdout, reader) |
| 170 |
- if err != nil && err != io.EOF {
|
|
| 170 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 171 | 171 |
log.Fatal(err) |
| 172 | 172 |
} |
| 173 | 173 |
} |
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"context" |
| 6 | 6 |
"encoding/json" |
| 7 |
+ "errors" |
|
| 7 | 8 |
"fmt" |
| 8 | 9 |
"io" |
| 9 | 10 |
"net/http" |
| ... | ... |
@@ -143,7 +144,7 @@ func TestEvents(t *testing.T) {
|
| 143 | 143 |
for {
|
| 144 | 144 |
select {
|
| 145 | 145 |
case err := <-errs: |
| 146 |
- if err != nil && err != io.EOF {
|
|
| 146 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 147 | 147 |
t.Fatal(err) |
| 148 | 148 |
} |
| 149 | 149 |
|
| ... | ... |
@@ -3,6 +3,7 @@ package client |
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 | 5 |
"context" |
| 6 |
+ "errors" |
|
| 6 | 7 |
"fmt" |
| 7 | 8 |
"io" |
| 8 | 9 |
"log" |
| ... | ... |
@@ -138,7 +139,7 @@ func ExampleClient_ServiceLogs_withTimeout() {
|
| 138 | 138 |
} |
| 139 | 139 |
|
| 140 | 140 |
_, err = io.Copy(os.Stdout, reader) |
| 141 |
- if err != nil && err != io.EOF {
|
|
| 141 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 142 | 142 |
log.Fatal(err) |
| 143 | 143 |
} |
| 144 | 144 |
} |
| ... | ... |
@@ -121,7 +121,7 @@ func (proxy *UDPProxy) replyLoop(cte *connTrackEntry, serverAddr net.IP, clientA |
| 121 | 121 |
again: |
| 122 | 122 |
read, err := cte.conn.Read(readBuf) |
| 123 | 123 |
if err != nil {
|
| 124 |
- if err, ok := err.(*net.OpError); ok && err.Err == syscall.ECONNREFUSED {
|
|
| 124 |
+ if err, ok := err.(*net.OpError); ok && errors.Is(err.Err, syscall.ECONNREFUSED) {
|
|
| 125 | 125 |
// This will happen if the last write failed |
| 126 | 126 |
// (e.g: nothing is actually listening on the |
| 127 | 127 |
// proxied port on the container), ignore it |
| ... | ... |
@@ -86,7 +86,7 @@ func (c *Config) CopyStreams(ctx context.Context, cfg *AttachConfig) <-chan erro |
| 86 | 86 |
} else {
|
| 87 | 87 |
_, err = pools.Copy(cfg.CStdin, cfg.Stdin) |
| 88 | 88 |
} |
| 89 |
- if err == io.ErrClosedPipe {
|
|
| 89 |
+ if errors.Is(err, io.ErrClosedPipe) {
|
|
| 90 | 90 |
err = nil |
| 91 | 91 |
} |
| 92 | 92 |
if err != nil {
|
| ... | ... |
@@ -109,7 +109,7 @@ func (c *Config) CopyStreams(ctx context.Context, cfg *AttachConfig) <-chan erro |
| 109 | 109 |
}() |
| 110 | 110 |
|
| 111 | 111 |
_, err := pools.Copy(stream, streamPipe) |
| 112 |
- if err == io.ErrClosedPipe {
|
|
| 112 |
+ if errors.Is(err, io.ErrClosedPipe) {
|
|
| 113 | 113 |
err = nil |
| 114 | 114 |
} |
| 115 | 115 |
if err != nil {
|
| ... | ... |
@@ -2,6 +2,7 @@ package bytespipe |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"testing" |
| 6 | 7 |
) |
| 7 | 8 |
|
| ... | ... |
@@ -42,7 +43,7 @@ func TestFixedBufferLen(t *testing.T) {
|
| 42 | 42 |
if n != 0 {
|
| 43 | 43 |
t.Fatalf("expected no bytes to be written to buffer, got %d", n)
|
| 44 | 44 |
} |
| 45 |
- if err != errBufferFull {
|
|
| 45 |
+ if !errors.Is(err, errBufferFull) {
|
|
| 46 | 46 |
t.Fatalf("expected errBufferFull, got %v", err)
|
| 47 | 47 |
} |
| 48 | 48 |
|
| ... | ... |
@@ -99,7 +100,7 @@ func TestFixedBufferWrite(t *testing.T) {
|
| 99 | 99 |
if n != 59 {
|
| 100 | 100 |
t.Fatalf("expected 59 bytes written before buffer is full, got %d", n)
|
| 101 | 101 |
} |
| 102 |
- if err != errBufferFull {
|
|
| 102 |
+ if !errors.Is(err, errBufferFull) {
|
|
| 103 | 103 |
t.Fatalf("expected errBufferFull, got %v - %v", err, buf.buf[:64])
|
| 104 | 104 |
} |
| 105 | 105 |
} |
| ... | ... |
@@ -354,7 +354,7 @@ func (c *Cluster) errNoManager(st nodeState) error {
|
| 354 | 354 |
if errors.Is(st.err, errSwarmLocked) {
|
| 355 | 355 |
return errSwarmLocked |
| 356 | 356 |
} |
| 357 |
- if st.err == errSwarmCertificatesExpired {
|
|
| 357 |
+ if errors.Is(st.err, errSwarmCertificatesExpired) {
|
|
| 358 | 358 |
return errSwarmCertificatesExpired |
| 359 | 359 |
} |
| 360 | 360 |
return errors.WithStack(notAvailableError(`This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.`)) |
| ... | ... |
@@ -426,7 +426,7 @@ func managerStats(client swarmapi.ControlClient, currentNodeID string) (current |
| 426 | 426 |
} |
| 427 | 427 |
|
| 428 | 428 |
func detectLockedError(err error) error {
|
| 429 |
- if err == swarmnode.ErrInvalidUnlockKey {
|
|
| 429 |
+ if errors.Is(err, swarmnode.ErrInvalidUnlockKey) {
|
|
| 430 | 430 |
return errors.WithStack(errSwarmLocked) |
| 431 | 431 |
} |
| 432 | 432 |
return err |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package convert |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"testing" |
| 5 | 6 |
|
| 6 | 7 |
containertypes "github.com/docker/docker/api/types/container" |
| ... | ... |
@@ -148,7 +149,7 @@ func TestServiceConvertToGRPCGenericRuntimeCustom(t *testing.T) {
|
| 148 | 148 |
}, |
| 149 | 149 |
} |
| 150 | 150 |
|
| 151 |
- if _, err := ServiceSpecToGRPC(s); err != ErrUnsupportedRuntime {
|
|
| 151 |
+ if _, err := ServiceSpecToGRPC(s); !errors.Is(err, ErrUnsupportedRuntime) {
|
|
| 152 | 152 |
t.Fatal(err) |
| 153 | 153 |
} |
| 154 | 154 |
} |
| ... | ... |
@@ -409,7 +410,7 @@ func TestServiceConvertToGRPCNetworkAttachmentRuntime(t *testing.T) {
|
| 409 | 409 |
if err == nil {
|
| 410 | 410 |
t.Fatalf("expected error %v but got no error", ErrUnsupportedRuntime)
|
| 411 | 411 |
} |
| 412 |
- if err != ErrUnsupportedRuntime {
|
|
| 412 |
+ if !errors.Is(err, ErrUnsupportedRuntime) {
|
|
| 413 | 413 |
t.Fatalf("expected error %v but got error %v", ErrUnsupportedRuntime, err)
|
| 414 | 414 |
} |
| 415 | 415 |
} |
| ... | ... |
@@ -436,7 +437,7 @@ func TestServiceConvertToGRPCMismatchedRuntime(t *testing.T) {
|
| 436 | 436 |
} |
| 437 | 437 |
s.TaskTemplate.Runtime = rt |
| 438 | 438 |
|
| 439 |
- if _, err := ServiceSpecToGRPC(s); err != ErrMismatchedRuntime {
|
|
| 439 |
+ if _, err := ServiceSpecToGRPC(s); !errors.Is(err, ErrMismatchedRuntime) {
|
|
| 440 | 440 |
t.Fatalf("expected %v got %v", ErrMismatchedRuntime, err)
|
| 441 | 441 |
} |
| 442 | 442 |
} |
| ... | ... |
@@ -305,7 +305,7 @@ func (r *controller) Wait(pctx context.Context) error {
|
| 305 | 305 |
go func() {
|
| 306 | 306 |
ectx, cancel := context.WithCancel(ctx) // cancel event context on first event |
| 307 | 307 |
defer cancel() |
| 308 |
- if err := r.checkHealth(ectx); err == ErrContainerUnhealthy {
|
|
| 308 |
+ if err := r.checkHealth(ectx); errors.Is(err, ErrContainerUnhealthy) {
|
|
| 309 | 309 |
healthErr <- ErrContainerUnhealthy |
| 310 | 310 |
if err := r.Shutdown(ectx); err != nil {
|
| 311 | 311 |
log.G(ectx).WithError(err).Debug("shutdown failed on unhealthy")
|
| ... | ... |
@@ -4,6 +4,7 @@ package container |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 | 6 |
"context" |
| 7 |
+ "errors" |
|
| 7 | 8 |
"testing" |
| 8 | 9 |
"time" |
| 9 | 10 |
|
| ... | ... |
@@ -80,7 +81,7 @@ func TestHealthStates(t *testing.T) {
|
| 80 | 80 |
|
| 81 | 81 |
select {
|
| 82 | 82 |
case err := <-errChan: |
| 83 |
- if err != expectedErr {
|
|
| 83 |
+ if !errors.Is(err, expectedErr) {
|
|
| 84 | 84 |
t.Fatalf("expect error %v, but get %v", expectedErr, err)
|
| 85 | 85 |
} |
| 86 | 86 |
case <-timer.C: |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package cluster |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
"net" |
| 6 | 7 |
"strings" |
| ... | ... |
@@ -26,7 +27,7 @@ func resolveListenAddr(specifiedAddr string) (string, string, error) {
|
| 26 | 26 |
// system? If so, use the address from that interface. |
| 27 | 27 |
specifiedIP, err := resolveInputIPAddr(specifiedHost, true) |
| 28 | 28 |
if err != nil {
|
| 29 |
- if err == errBadNetworkIdentifier {
|
|
| 29 |
+ if errors.Is(err, errBadNetworkIdentifier) {
|
|
| 30 | 30 |
err = errBadListenAddr |
| 31 | 31 |
} |
| 32 | 32 |
return "", "", err |
| ... | ... |
@@ -57,7 +58,7 @@ func (c *Cluster) resolveAdvertiseAddr(advertiseAddr, listenAddrPort string) (st |
| 57 | 57 |
// system? If so, use the address from that interface. |
| 58 | 58 |
advertiseIP, err := resolveInputIPAddr(advertiseHost, false) |
| 59 | 59 |
if err != nil {
|
| 60 |
- if err == errBadNetworkIdentifier {
|
|
| 60 |
+ if errors.Is(err, errBadNetworkIdentifier) {
|
|
| 61 | 61 |
err = errBadAdvertiseAddr |
| 62 | 62 |
} |
| 63 | 63 |
return "", "", err |
| ... | ... |
@@ -72,7 +73,7 @@ func (c *Cluster) resolveAdvertiseAddr(advertiseAddr, listenAddrPort string) (st |
| 72 | 72 |
// that interface. |
| 73 | 73 |
defaultAdvertiseIP, err := resolveInputIPAddr(c.config.DefaultAdvertiseAddr, false) |
| 74 | 74 |
if err != nil {
|
| 75 |
- if err == errBadNetworkIdentifier {
|
|
| 75 |
+ if errors.Is(err, errBadNetworkIdentifier) {
|
|
| 76 | 76 |
err = errBadDefaultAdvertiseAddr |
| 77 | 77 |
} |
| 78 | 78 |
return "", "", err |
| ... | ... |
@@ -151,7 +152,7 @@ func resolveDataPathAddr(dataPathAddr string) (string, error) {
|
| 151 | 151 |
// If a data path flag is specified try to resolve the IP address. |
| 152 | 152 |
dataPathIP, err := resolveInputIPAddr(dataPathAddr, false) |
| 153 | 153 |
if err != nil {
|
| 154 |
- if err == errBadNetworkIdentifier {
|
|
| 154 |
+ if errors.Is(err, errBadNetworkIdentifier) {
|
|
| 155 | 155 |
err = errBadDataPathAddr |
| 156 | 156 |
} |
| 157 | 157 |
return "", err |
| ... | ... |
@@ -216,7 +217,7 @@ func resolveInputIPAddr(input string, isUnspecifiedValid bool) (net.IP, error) {
|
| 216 | 216 |
return interfaceAddr, nil |
| 217 | 217 |
} |
| 218 | 218 |
// String matched interface but there is a potential ambiguity to be resolved |
| 219 |
- if err != errNoSuchInterface {
|
|
| 219 |
+ if !errors.Is(err, errNoSuchInterface) {
|
|
| 220 | 220 |
return nil, err |
| 221 | 221 |
} |
| 222 | 222 |
|
| ... | ... |
@@ -513,7 +513,7 @@ func (c *Cluster) ServiceLogs(ctx context.Context, selector *backend.LogSelector |
| 513 | 513 |
default: |
| 514 | 514 |
} |
| 515 | 515 |
subscribeMsg, err := stream.Recv() |
| 516 |
- if err == io.EOF {
|
|
| 516 |
+ if errors.Is(err, io.EOF) {
|
|
| 517 | 517 |
return |
| 518 | 518 |
} |
| 519 | 519 |
// if we're not io.EOF, push the message in and return |
| ... | ... |
@@ -314,7 +314,7 @@ func (c *Cluster) UnlockSwarm(req types.UnlockRequest) error {
|
| 314 | 314 |
if !state.IsActiveManager() {
|
| 315 | 315 |
// when manager is not active, |
| 316 | 316 |
// unless it is locked, otherwise return error. |
| 317 |
- if err := c.errNoManager(state); err != errSwarmLocked {
|
|
| 317 |
+ if err := c.errNoManager(state); !errors.Is(err, errSwarmLocked) {
|
|
| 318 | 318 |
c.mu.RUnlock() |
| 319 | 319 |
return err |
| 320 | 320 |
} |
| ... | ... |
@@ -462,7 +462,7 @@ func killProcessDirectly(ctr *container.Container) error {
|
| 462 | 462 |
} |
| 463 | 463 |
|
| 464 | 464 |
if err := unix.Kill(pid, syscall.SIGKILL); err != nil {
|
| 465 |
- if err != unix.ESRCH {
|
|
| 465 |
+ if !errors.Is(err, unix.ESRCH) {
|
|
| 466 | 466 |
return errdefs.System(err) |
| 467 | 467 |
} |
| 468 | 468 |
err = errNoSuchProcess{pid, syscall.SIGKILL}
|
| ... | ... |
@@ -102,7 +102,7 @@ func (c cacheAdaptor) Get(id image.ID) (*image.Image, error) {
|
| 102 | 102 |
} |
| 103 | 103 |
return nil |
| 104 | 104 |
}) |
| 105 |
- if err != nil && err != errFound {
|
|
| 105 |
+ if err != nil && !errors.Is(err, errFound) {
|
|
| 106 | 106 |
return nil, err |
| 107 | 107 |
} |
| 108 | 108 |
|
| ... | ... |
@@ -217,7 +217,7 @@ func findContentByUncompressedDigest(ctx context.Context, cs content.Manager, un |
| 217 | 217 |
return errStopWalk |
| 218 | 218 |
}, `labels."containerd.io/uncompressed"==`+uncompressed.String()) |
| 219 | 219 |
|
| 220 |
- if err != nil && err != errStopWalk {
|
|
| 220 |
+ if err != nil && !errors.Is(err, errStopWalk) {
|
|
| 221 | 221 |
return out, err |
| 222 | 222 |
} |
| 223 | 223 |
if out.Digest == "" {
|
| ... | ... |
@@ -699,7 +699,7 @@ func setupLabelFilter(ctx context.Context, store content.Store, fltrs filters.Ar |
| 699 | 699 |
return nil, errFoundConfig |
| 700 | 700 |
})), nil, image.Target) |
| 701 | 701 |
|
| 702 |
- if err == errFoundConfig {
|
|
| 702 |
+ if errors.Is(err, errFoundConfig) {
|
|
| 703 | 703 |
return true |
| 704 | 704 |
} |
| 705 | 705 |
if err != nil {
|
| ... | ... |
@@ -31,7 +31,7 @@ func (i *ImageService) walkImageManifests(ctx context.Context, img c8dimages.Ima |
| 31 | 31 |
handleManifest := func(ctx context.Context, d ocispec.Descriptor) error {
|
| 32 | 32 |
platformImg, err := i.NewImageManifest(ctx, img, d) |
| 33 | 33 |
if err != nil {
|
| 34 |
- if err == errNotManifest {
|
|
| 34 |
+ if errors.Is(err, errNotManifest) {
|
|
| 35 | 35 |
return nil |
| 36 | 36 |
} |
| 37 | 37 |
return err |
| ... | ... |
@@ -59,7 +59,7 @@ func (i *ImageService) walkReachableImageManifests(ctx context.Context, img c8di |
| 59 | 59 |
handleManifest := func(ctx context.Context, d ocispec.Descriptor) error {
|
| 60 | 60 |
platformImg, err := i.NewImageManifest(ctx, img, d) |
| 61 | 61 |
if err != nil {
|
| 62 |
- if err == errNotManifest {
|
|
| 62 |
+ if errors.Is(err, errNotManifest) {
|
|
| 63 | 63 |
return nil |
| 64 | 64 |
} |
| 65 | 65 |
return err |
| ... | ... |
@@ -49,7 +49,7 @@ func copyRegular(srcPath, dstPath string, fileinfo os.FileInfo, copyWithFileRang |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
*copyWithFileClone = false |
| 52 |
- if err == unix.EXDEV {
|
|
| 52 |
+ if errors.Is(err, unix.EXDEV) {
|
|
| 53 | 53 |
*copyWithFileRange = false |
| 54 | 54 |
} |
| 55 | 55 |
} |
| ... | ... |
@@ -57,7 +57,7 @@ func copyRegular(srcPath, dstPath string, fileinfo os.FileInfo, copyWithFileRang |
| 57 | 57 |
err = doCopyWithFileRange(srcFile, dstFile, fileinfo) |
| 58 | 58 |
// Trying the file_clone may not have caught the exdev case |
| 59 | 59 |
// as the ioctl may not have been available (therefore EINVAL) |
| 60 |
- if err == unix.EXDEV || err == unix.ENOSYS {
|
|
| 60 |
+ if errors.Is(err, unix.EXDEV) || errors.Is(err, unix.ENOSYS) {
|
|
| 61 | 61 |
*copyWithFileRange = false |
| 62 | 62 |
} else {
|
| 63 | 63 |
return err |
| ... | ... |
@@ -5,6 +5,7 @@ package graphtest |
| 5 | 5 |
import ( |
| 6 | 6 |
"bytes" |
| 7 | 7 |
"crypto/rand" |
| 8 |
+ "errors" |
|
| 8 | 9 |
"os" |
| 9 | 10 |
"path" |
| 10 | 11 |
"testing" |
| ... | ... |
@@ -312,7 +313,7 @@ func DriverTestSetQuota(t *testing.T, drivername string, required bool) {
|
| 312 | 312 |
createOpts.StorageOpt = make(map[string]string, 1) |
| 313 | 313 |
createOpts.StorageOpt["size"] = "50M" |
| 314 | 314 |
layerName := drivername + "Test" |
| 315 |
- if err := driver.CreateReadWrite(layerName, "Base", createOpts); err == quota.ErrQuotaNotSupported && !required {
|
|
| 315 |
+ if err := driver.CreateReadWrite(layerName, "Base", createOpts); errors.Is(err, quota.ErrQuotaNotSupported) && !required {
|
|
| 316 | 316 |
t.Skipf("Quota not supported on underlying filesystem: %v", err)
|
| 317 | 317 |
} else if err != nil {
|
| 318 | 318 |
t.Fatal(err) |
| ... | ... |
@@ -337,7 +338,7 @@ func DriverTestSetQuota(t *testing.T, drivername string, required bool) {
|
| 337 | 337 |
if err == nil {
|
| 338 | 338 |
t.Fatalf("expected write to fail(), instead had success")
|
| 339 | 339 |
} |
| 340 |
- if pathError, ok := err.(*os.PathError); ok && pathError.Err != unix.EDQUOT && pathError.Err != unix.ENOSPC {
|
|
| 340 |
+ if pathError, ok := err.(*os.PathError); ok && !errors.Is(pathError.Err, unix.EDQUOT) && !errors.Is(pathError.Err, unix.ENOSPC) {
|
|
| 341 | 341 |
os.Remove(path.Join(mountPath, "bigfile")) |
| 342 | 342 |
t.Fatalf("expect write() to fail with %v or %v, got %v", unix.EDQUOT, unix.ENOSPC, pathError.Err)
|
| 343 | 343 |
} |
| ... | ... |
@@ -106,7 +106,7 @@ func doesSupportNativeDiff(d string) error {
|
| 106 | 106 |
// rename "d1" to "d2" |
| 107 | 107 |
if err := os.Rename(filepath.Join(td, mergedDirName, "d1"), filepath.Join(td, mergedDirName, "d2")); err != nil {
|
| 108 | 108 |
// if rename failed with syscall.EXDEV, the kernel doesn't have CONFIG_OVERLAY_FS_REDIRECT_DIR enabled |
| 109 |
- if err.(*os.LinkError).Err == syscall.EXDEV {
|
|
| 109 |
+ if errors.Is(err.(*os.LinkError).Err, syscall.EXDEV) {
|
|
| 110 | 110 |
return nil |
| 111 | 111 |
} |
| 112 | 112 |
return errors.Wrap(err, "failed to rename dir in merged directory") |
| ... | ... |
@@ -2,6 +2,7 @@ package vfs |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "errors" |
|
| 5 | 6 |
|
| 6 | 7 |
"github.com/containerd/log" |
| 7 | 8 |
"github.com/docker/docker/quota" |
| ... | ... |
@@ -15,7 +16,7 @@ type driverQuota struct {
|
| 15 | 15 |
func setupDriverQuota(driver *Driver) {
|
| 16 | 16 |
if quotaCtl, err := quota.NewControl(driver.home); err == nil {
|
| 17 | 17 |
driver.quotaCtl = quotaCtl |
| 18 |
- } else if err != quota.ErrQuotaNotSupported {
|
|
| 18 |
+ } else if !errors.Is(err, quota.ErrQuotaNotSupported) {
|
|
| 19 | 19 |
log.G(context.TODO()).Warnf("Unable to setup quota: %v\n", err)
|
| 20 | 20 |
} |
| 21 | 21 |
} |
| ... | ... |
@@ -524,7 +524,7 @@ func includeContainerInList(container *container.Snapshot, filter *listContext) |
| 524 | 524 |
} |
| 525 | 525 |
return nil |
| 526 | 526 |
}) |
| 527 |
- if err != volumeExist {
|
|
| 527 |
+ if !errors.Is(err, volumeExist) {
|
|
| 528 | 528 |
return excludeContainer |
| 529 | 529 |
} |
| 530 | 530 |
} |
| ... | ... |
@@ -560,7 +560,7 @@ func includeContainerInList(container *container.Snapshot, filter *listContext) |
| 560 | 560 |
} |
| 561 | 561 |
return nil |
| 562 | 562 |
}) |
| 563 |
- if err != networkExist {
|
|
| 563 |
+ if !errors.Is(err, networkExist) {
|
|
| 564 | 564 |
return excludeContainer |
| 565 | 565 |
} |
| 566 | 566 |
} |
| ... | ... |
@@ -107,7 +107,7 @@ func (a *pluginAdapterWithRead) ReadLogs(ctx context.Context, config ReadConfig) |
| 107 | 107 |
|
| 108 | 108 |
var buf logdriver.LogEntry |
| 109 | 109 |
if err := dec.Decode(&buf); err != nil {
|
| 110 |
- if err == io.EOF {
|
|
| 110 |
+ if errors.Is(err, io.EOF) {
|
|
| 111 | 111 |
return |
| 112 | 112 |
} |
| 113 | 113 |
watcher.Err <- errors.Wrap(err, "error decoding log message") |
| ... | ... |
@@ -3,6 +3,7 @@ package logger |
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"encoding/binary" |
| 6 |
+ "errors" |
|
| 6 | 7 |
"io" |
| 7 | 8 |
"sync" |
| 8 | 9 |
"testing" |
| ... | ... |
@@ -118,7 +119,7 @@ func (l *mockLoggingPlugin) waitLen(i int) {
|
| 118 | 118 |
} |
| 119 | 119 |
|
| 120 | 120 |
func (l *mockLoggingPlugin) check(t *testing.T) {
|
| 121 |
- if l.err != nil && l.err != io.EOF {
|
|
| 121 |
+ if l.err != nil && !errors.Is(l.err, io.EOF) {
|
|
| 122 | 122 |
t.Fatal(l.err) |
| 123 | 123 |
} |
| 124 | 124 |
} |
| ... | ... |
@@ -431,7 +431,7 @@ func (l *logStream) Log(msg *logger.Message) error {
|
| 431 | 431 |
// (i.e. returns false) in this case. |
| 432 | 432 |
ctx := context.TODO() |
| 433 | 433 |
if err := l.messages.Enqueue(ctx, msg); err != nil {
|
| 434 |
- if err == loggerutils.ErrQueueClosed {
|
|
| 434 |
+ if errors.Is(err, loggerutils.ErrQueueClosed) {
|
|
| 435 | 435 |
return errClosed |
| 436 | 436 |
} |
| 437 | 437 |
return err |
| ... | ... |
@@ -2,6 +2,7 @@ package gcplogs |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"fmt" |
| 6 | 7 |
"sync" |
| 7 | 8 |
"sync/atomic" |
| ... | ... |
@@ -187,7 +188,7 @@ func New(info logger.Info) (logger.Logger, error) {
|
| 187 | 187 |
// without overly spamming /var/log/docker.log so we log the first time |
| 188 | 188 |
// we overflow and every 1000th time after. |
| 189 | 189 |
c.OnError = func(err error) {
|
| 190 |
- if err == logging.ErrOverflow {
|
|
| 190 |
+ if errors.Is(err, logging.ErrOverflow) {
|
|
| 191 | 191 |
if i := droppedLogs.Add(1); i%1000 == 1 {
|
| 192 | 192 |
log.G(context.TODO()).Errorf("gcplogs driver has dropped %v logs", i)
|
| 193 | 193 |
} |
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"bufio" |
| 5 | 5 |
"bytes" |
| 6 | 6 |
"context" |
| 7 |
+ "errors" |
|
| 7 | 8 |
"fmt" |
| 8 | 9 |
"io" |
| 9 | 10 |
"os" |
| ... | ... |
@@ -104,7 +105,7 @@ func TestEncodeDecode(t *testing.T) {
|
| 104 | 104 |
assert.Assert(t, string(msg.Line) == "hello 3\n") |
| 105 | 105 |
|
| 106 | 106 |
_, err = dec.Decode() |
| 107 |
- assert.Assert(t, err == io.EOF) |
|
| 107 |
+ assert.Assert(t, errors.Is(err, io.EOF)) |
|
| 108 | 108 |
} |
| 109 | 109 |
|
| 110 | 110 |
func TestReadLogs(t *testing.T) {
|
| ... | ... |
@@ -46,7 +46,7 @@ func getTailReader(ctx context.Context, r loggerutils.SizeReaderAt, req int) (lo |
| 46 | 46 |
} |
| 47 | 47 |
|
| 48 | 48 |
n, err := r.ReadAt(buf, offset-encodeBinaryLen64) |
| 49 |
- if err != nil && err != io.EOF {
|
|
| 49 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 50 | 50 |
return nil, 0, errors.Wrap(err, "error reading log message footer") |
| 51 | 51 |
} |
| 52 | 52 |
|
| ... | ... |
@@ -57,7 +57,7 @@ func getTailReader(ctx context.Context, r loggerutils.SizeReaderAt, req int) (lo |
| 57 | 57 |
msgLen := binary.BigEndian.Uint32(buf) |
| 58 | 58 |
|
| 59 | 59 |
n, err = r.ReadAt(buf, offset-encodeBinaryLen64-encodeBinaryLen64-int64(msgLen)) |
| 60 |
- if err != nil && err != io.EOF {
|
|
| 60 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 61 | 61 |
return nil, 0, errors.Wrap(err, "error reading log message header") |
| 62 | 62 |
} |
| 63 | 63 |
|
| ... | ... |
@@ -2,6 +2,7 @@ package logger |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"strconv" |
| 6 | 7 |
"testing" |
| 7 | 8 |
"time" |
| ... | ... |
@@ -97,7 +98,7 @@ func TestRingClose(t *testing.T) {
|
| 97 | 97 |
t.Fatal(err) |
| 98 | 98 |
} |
| 99 | 99 |
r.Close() |
| 100 |
- if err := r.Enqueue(&Message{}); err != errClosed {
|
|
| 100 |
+ if err := r.Enqueue(&Message{}); !errors.Is(err, errClosed) {
|
|
| 101 | 101 |
t.Fatalf("expected errClosed, got: %v", err)
|
| 102 | 102 |
} |
| 103 | 103 |
if len(r.queue) != 1 {
|
| ... | ... |
@@ -153,7 +153,7 @@ func (daemon *Daemon) handleContainerExit(c *container.Container, e *libcontaine |
| 153 | 153 |
c.CheckpointTo(context.TODO(), daemon.containersReplica) |
| 154 | 154 |
c.Unlock() |
| 155 | 155 |
defer daemon.autoRemove(&cfg.Config, c) |
| 156 |
- if waitErr != restartmanager.ErrRestartCanceled {
|
|
| 156 |
+ if !errors.Is(waitErr, restartmanager.ErrRestartCanceled) {
|
|
| 157 | 157 |
log.G(ctx).Errorf("restartmanger wait error: %+v", waitErr)
|
| 158 | 158 |
} |
| 159 | 159 |
} |
| ... | ... |
@@ -164,15 +164,15 @@ func retryOnError(err error) error {
|
| 164 | 164 |
return xfer.DoNotRetry{Err: err}
|
| 165 | 165 |
} |
| 166 | 166 |
case *url.Error: |
| 167 |
- switch v.Err {
|
|
| 168 |
- case auth.ErrNoBasicAuthCredentials, auth.ErrNoToken: |
|
| 167 |
+ switch {
|
|
| 168 |
+ case errors.Is(v.Err, auth.ErrNoBasicAuthCredentials), errors.Is(v.Err, auth.ErrNoToken): |
|
| 169 | 169 |
return xfer.DoNotRetry{Err: v.Err}
|
| 170 | 170 |
} |
| 171 | 171 |
return retryOnError(v.Err) |
| 172 | 172 |
case *client.UnexpectedHTTPResponseError, unsupportedMediaTypeError: |
| 173 | 173 |
return xfer.DoNotRetry{Err: err}
|
| 174 | 174 |
case error: |
| 175 |
- if err == distribution.ErrBlobUnknown {
|
|
| 175 |
+ if errors.Is(err, distribution.ErrBlobUnknown) {
|
|
| 176 | 176 |
return xfer.DoNotRetry{Err: err}
|
| 177 | 177 |
} |
| 178 | 178 |
if strings.Contains(err.Error(), strings.ToLower(syscall.ENOSPC.Error())) {
|
| ... | ... |
@@ -65,7 +65,7 @@ func addDigestReference(store refstore.Store, ref reference.Named, dgst digest.D |
| 65 | 65 |
log.G(context.TODO()).Errorf("Image ID for digest %s changed from %s to %s, cannot update", dgst.String(), oldTagID, id)
|
| 66 | 66 |
} |
| 67 | 67 |
return nil |
| 68 |
- } else if err != refstore.ErrDoesNotExist {
|
|
| 68 |
+ } else if !errors.Is(err, refstore.ErrDoesNotExist) {
|
|
| 69 | 69 |
return err |
| 70 | 70 |
} |
| 71 | 71 |
|
| ... | ... |
@@ -248,7 +248,7 @@ func (ld *layerDescriptor) Download(ctx context.Context, progressOutput progress |
| 248 | 248 |
|
| 249 | 249 |
_, err = io.Copy(tmpFile, io.TeeReader(reader, ld.verifier)) |
| 250 | 250 |
if err != nil {
|
| 251 |
- if err == transport.ErrWrongCodeForByteRange {
|
|
| 251 |
+ if errors.Is(err, transport.ErrWrongCodeForByteRange) {
|
|
| 252 | 252 |
if err := ld.truncateDownloadFile(); err != nil {
|
| 253 | 253 |
return nil, 0, xfer.DoNotRetry{Err: err}
|
| 254 | 254 |
} |
| ... | ... |
@@ -421,7 +421,7 @@ func (p *puller) pullTag(ctx context.Context, ref reference.Named, platform *oci |
| 421 | 421 |
if oldTagID == id {
|
| 422 | 422 |
return false, addDigestReference(p.config.ReferenceStore, ref, manifestDigest, id) |
| 423 | 423 |
} |
| 424 |
- } else if err != refstore.ErrDoesNotExist {
|
|
| 424 |
+ } else if !errors.Is(err, refstore.ErrDoesNotExist) {
|
|
| 425 | 425 |
return false, err |
| 426 | 426 |
} |
| 427 | 427 |
|
| ... | ... |
@@ -525,8 +525,8 @@ attempts: |
| 525 | 525 |
var err error |
| 526 | 526 |
desc, err = pd.repo.Blobs(ctx).Stat(ctx, dgst) |
| 527 | 527 |
pd.checkedDigests[meta.Digest] = struct{}{}
|
| 528 |
- switch err {
|
|
| 529 |
- case nil: |
|
| 528 |
+ switch {
|
|
| 529 |
+ case err == nil: |
|
| 530 | 530 |
if m, ok := digestToMetadata[desc.Digest]; !ok || m.SourceRepository != pd.repoName.Name() || !metadata.CheckV2MetadataHMAC(m, pd.hmacKey) {
|
| 531 | 531 |
// cache mapping from this layer's DiffID to the blobsum |
| 532 | 532 |
if err := pd.metadataService.TagAndAdd(diffID, pd.hmacKey, metadata.V2Metadata{
|
| ... | ... |
@@ -539,7 +539,7 @@ attempts: |
| 539 | 539 |
desc.MediaType = schema2.MediaTypeLayer |
| 540 | 540 |
exists = true |
| 541 | 541 |
break attempts |
| 542 |
- case distribution.ErrBlobUnknown: |
|
| 542 |
+ case errors.Is(err, distribution.ErrBlobUnknown): |
|
| 543 | 543 |
if meta.SourceRepository == pd.repoName.Name() {
|
| 544 | 544 |
// remove the mapping to the target repository |
| 545 | 545 |
if err := pd.metadataService.Remove(*meta); err != nil {
|
| ... | ... |
@@ -351,7 +351,7 @@ func TestCancelledDownload(t *testing.T) {
|
| 351 | 351 |
|
| 352 | 352 |
descriptors := downloadDescriptors(nil) |
| 353 | 353 |
_, _, err := ldm.Download(ctx, *image.NewRootFS(), descriptors, progress.ChanOutput(progressChan)) |
| 354 |
- if err != context.Canceled {
|
|
| 354 |
+ if !errors.Is(err, context.Canceled) {
|
|
| 355 | 355 |
close(progressChan) |
| 356 | 356 |
t.Fatal("expected download to be cancelled")
|
| 357 | 357 |
} |
| ... | ... |
@@ -125,7 +125,7 @@ func TestCancelledUpload(t *testing.T) {
|
| 125 | 125 |
|
| 126 | 126 |
descriptors := uploadDescriptors(nil) |
| 127 | 127 |
err := lum.Upload(ctx, descriptors, progress.ChanOutput(progressChan)) |
| 128 |
- if err != context.Canceled {
|
|
| 128 |
+ if !errors.Is(err, context.Canceled) {
|
|
| 129 | 129 |
t.Fatal("expected upload to be cancelled")
|
| 130 | 130 |
} |
| 131 | 131 |
|
| ... | ... |
@@ -22,7 +22,7 @@ func TestNotFound(t *testing.T) {
|
| 22 | 22 |
if !cerrdefs.IsNotFound(e) {
|
| 23 | 23 |
t.Fatalf("expected not found error, got: %T", e)
|
| 24 | 24 |
} |
| 25 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 25 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 26 | 26 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 27 | 27 |
} |
| 28 | 28 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -43,7 +43,7 @@ func TestConflict(t *testing.T) {
|
| 43 | 43 |
if !cerrdefs.IsConflict(e) {
|
| 44 | 44 |
t.Fatalf("expected conflict error, got: %T", e)
|
| 45 | 45 |
} |
| 46 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 46 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 47 | 47 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 48 | 48 |
} |
| 49 | 49 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -64,7 +64,7 @@ func TestForbidden(t *testing.T) {
|
| 64 | 64 |
if !cerrdefs.IsPermissionDenied(e) {
|
| 65 | 65 |
t.Fatalf("expected forbidden error, got: %T", e)
|
| 66 | 66 |
} |
| 67 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 67 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 68 | 68 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 69 | 69 |
} |
| 70 | 70 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -85,7 +85,7 @@ func TestInvalidParameter(t *testing.T) {
|
| 85 | 85 |
if !cerrdefs.IsInvalidArgument(e) {
|
| 86 | 86 |
t.Fatalf("expected invalid argument error, got %T", e)
|
| 87 | 87 |
} |
| 88 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 88 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 89 | 89 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 90 | 90 |
} |
| 91 | 91 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -106,7 +106,7 @@ func TestNotImplemented(t *testing.T) {
|
| 106 | 106 |
if !cerrdefs.IsNotImplemented(e) {
|
| 107 | 107 |
t.Fatalf("expected not implemented error, got %T", e)
|
| 108 | 108 |
} |
| 109 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 109 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 110 | 110 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 111 | 111 |
} |
| 112 | 112 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -127,7 +127,7 @@ func TestNotModified(t *testing.T) {
|
| 127 | 127 |
if !cerrdefs.IsNotModified(e) {
|
| 128 | 128 |
t.Fatalf("expected not modified error, got %T", e)
|
| 129 | 129 |
} |
| 130 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 130 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 131 | 131 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 132 | 132 |
} |
| 133 | 133 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -148,7 +148,7 @@ func TestUnauthorized(t *testing.T) {
|
| 148 | 148 |
if !cerrdefs.IsUnauthorized(e) {
|
| 149 | 149 |
t.Fatalf("expected unauthorized error, got %T", e)
|
| 150 | 150 |
} |
| 151 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 151 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 152 | 152 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 153 | 153 |
} |
| 154 | 154 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -169,7 +169,7 @@ func TestUnknown(t *testing.T) {
|
| 169 | 169 |
if !cerrdefs.IsUnknown(e) {
|
| 170 | 170 |
t.Fatalf("expected unknown error, got %T", e)
|
| 171 | 171 |
} |
| 172 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 172 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 173 | 173 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 174 | 174 |
} |
| 175 | 175 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -190,7 +190,7 @@ func TestCancelled(t *testing.T) {
|
| 190 | 190 |
if !cerrdefs.IsCanceled(e) {
|
| 191 | 191 |
t.Fatalf("expected cancelled error, got %T", e)
|
| 192 | 192 |
} |
| 193 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 193 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 194 | 194 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 195 | 195 |
} |
| 196 | 196 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -211,7 +211,7 @@ func TestDeadline(t *testing.T) {
|
| 211 | 211 |
if !cerrdefs.IsDeadlineExceeded(e) {
|
| 212 | 212 |
t.Fatalf("expected deadline error, got %T", e)
|
| 213 | 213 |
} |
| 214 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 214 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 215 | 215 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 216 | 216 |
} |
| 217 | 217 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -232,7 +232,7 @@ func TestDataLoss(t *testing.T) {
|
| 232 | 232 |
if !cerrdefs.IsDataLoss(e) {
|
| 233 | 233 |
t.Fatalf("expected data loss error, got %T", e)
|
| 234 | 234 |
} |
| 235 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 235 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 236 | 236 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 237 | 237 |
} |
| 238 | 238 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -253,7 +253,7 @@ func TestUnavailable(t *testing.T) {
|
| 253 | 253 |
if !cerrdefs.IsUnavailable(e) {
|
| 254 | 254 |
t.Fatalf("expected unavaillable error, got %T", e)
|
| 255 | 255 |
} |
| 256 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 256 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 257 | 257 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 258 | 258 |
} |
| 259 | 259 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -274,7 +274,7 @@ func TestSystem(t *testing.T) {
|
| 274 | 274 |
if !cerrdefs.IsInternal(e) {
|
| 275 | 275 |
t.Fatalf("expected system error, got %T", e)
|
| 276 | 276 |
} |
| 277 |
- if cause := e.(wrapped).Unwrap(); cause != errTest {
|
|
| 277 |
+ if cause := e.(wrapped).Unwrap(); cause != errTest { //nolint:errorlint // not using errors.Is, as this tests for the unwrapped error.
|
|
| 278 | 278 |
t.Fatalf("causual should be errTest, got: %v", cause)
|
| 279 | 279 |
} |
| 280 | 280 |
if !errors.Is(e, errTest) {
|
| ... | ... |
@@ -199,7 +199,7 @@ func (imageNotFoundError) NotFound() {}
|
| 199 | 199 |
func (is *store) Search(term string) (ID, error) {
|
| 200 | 200 |
dgst, err := is.digestSet.Lookup(term) |
| 201 | 201 |
if err != nil {
|
| 202 |
- if err == digestset.ErrDigestNotFound {
|
|
| 202 |
+ if errors.Is(err, digestset.ErrDigestNotFound) {
|
|
| 203 | 203 |
err = imageNotFoundError(term) |
| 204 | 204 |
} |
| 205 | 205 |
return "", errors.WithStack(err) |
| ... | ... |
@@ -71,7 +71,7 @@ func (s *DockerAPISuite) TestExecResizeImmediatelyAfterExecStart(c *testing.T) {
|
| 71 | 71 |
_, rc, err := request.Post(testutil.GetContext(c), fmt.Sprintf("/exec/%s/resize?h=24&w=80", execID), request.ContentType("text/plain"))
|
| 72 | 72 |
if err != nil {
|
| 73 | 73 |
// It's probably a panic of the daemon if io.ErrUnexpectedEOF is returned. |
| 74 |
- if err == io.ErrUnexpectedEOF {
|
|
| 74 |
+ if errors.Is(err, io.ErrUnexpectedEOF) {
|
|
| 75 | 75 |
return errors.New("the daemon might have crashed")
|
| 76 | 76 |
} |
| 77 | 77 |
// Other error happened, should be reported. |
| ... | ... |
@@ -3,6 +3,7 @@ |
| 3 | 3 |
package main |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
+ "errors" |
|
| 6 | 7 |
"strings" |
| 7 | 8 |
"testing" |
| 8 | 9 |
|
| ... | ... |
@@ -143,7 +144,7 @@ func (s *DockerDaemonSuite) TestDaemonShutdownWithPlugins(c *testing.T) {
|
| 143 | 143 |
} |
| 144 | 144 |
|
| 145 | 145 |
for {
|
| 146 |
- if err := unix.Kill(s.d.Pid(), 0); err == unix.ESRCH {
|
|
| 146 |
+ if err := unix.Kill(s.d.Pid(), 0); errors.Is(err, unix.ESRCH) {
|
|
| 147 | 147 |
break |
| 148 | 148 |
} |
| 149 | 149 |
} |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"bytes" |
| 6 | 6 |
"context" |
| 7 | 7 |
"encoding/json" |
| 8 |
+ "errors" |
|
| 8 | 9 |
"fmt" |
| 9 | 10 |
"io" |
| 10 | 11 |
"net" |
| ... | ... |
@@ -2190,7 +2191,7 @@ func (s *DockerCLIRunSuite) TestRunVolumesCleanPaths(c *testing.T) {
|
| 2190 | 2190 |
cli.DockerCmd(c, "run", "-v", prefix+"/foo", "-v", prefix+"/bar/", "--name", "dark_helmet", "run_volumes_clean_paths") |
| 2191 | 2191 |
|
| 2192 | 2192 |
out, err := inspectMountSourceField("dark_helmet", prefix+slash+"foo"+slash)
|
| 2193 |
- if err != errMountNotFound {
|
|
| 2193 |
+ if !errors.Is(err, errMountNotFound) {
|
|
| 2194 | 2194 |
c.Fatalf("Found unexpected volume entry for '%s/foo/' in volumes\n%q", prefix, out)
|
| 2195 | 2195 |
} |
| 2196 | 2196 |
|
| ... | ... |
@@ -2201,7 +2202,7 @@ func (s *DockerCLIRunSuite) TestRunVolumesCleanPaths(c *testing.T) {
|
| 2201 | 2201 |
} |
| 2202 | 2202 |
|
| 2203 | 2203 |
out, err = inspectMountSourceField("dark_helmet", prefix+slash+"bar"+slash)
|
| 2204 |
- if err != errMountNotFound {
|
|
| 2204 |
+ if !errors.Is(err, errMountNotFound) {
|
|
| 2205 | 2205 |
c.Fatalf("Found unexpected volume entry for '%s/bar/' in volumes\n%q", prefix, out)
|
| 2206 | 2206 |
} |
| 2207 | 2207 |
|
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"bytes" |
| 6 | 6 |
"context" |
| 7 | 7 |
"encoding/json" |
| 8 |
+ "errors" |
|
| 8 | 9 |
"fmt" |
| 9 | 10 |
"io" |
| 10 | 11 |
"os" |
| ... | ... |
@@ -780,7 +781,7 @@ func TestBuildEmitsImageCreateEvent(t *testing.T) {
|
| 780 | 780 |
imageCreateEvts++ |
| 781 | 781 |
} |
| 782 | 782 |
case err := <-errs: |
| 783 |
- assert.Check(t, err == nil || err == io.EOF) |
|
| 783 |
+ assert.Check(t, err == nil || errors.Is(err, io.EOF)) |
|
| 784 | 784 |
finished = true |
| 785 | 785 |
} |
| 786 | 786 |
} |
| ... | ... |
@@ -5,6 +5,7 @@ import ( |
| 5 | 5 |
"bytes" |
| 6 | 6 |
"context" |
| 7 | 7 |
"encoding/json" |
| 8 |
+ "errors" |
|
| 8 | 9 |
"io" |
| 9 | 10 |
"os" |
| 10 | 11 |
"path/filepath" |
| ... | ... |
@@ -335,7 +336,7 @@ func TestCopyFromContainer(t *testing.T) {
|
| 335 | 335 |
tr := tar.NewReader(rdr) |
| 336 | 336 |
for numFound < len(x.expect) {
|
| 337 | 337 |
h, err := tr.Next() |
| 338 |
- if err == io.EOF {
|
|
| 338 |
+ if errors.Is(err, io.EOF) {
|
|
| 339 | 339 |
break |
| 340 | 340 |
} |
| 341 | 341 |
assert.NilError(t, err) |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package container |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"io" |
| 5 | 6 |
"testing" |
| 6 | 7 |
|
| ... | ... |
@@ -80,7 +81,7 @@ func getEventActions(t *testing.T, messages <-chan events.Message, errs <-chan e |
| 80 | 80 |
for {
|
| 81 | 81 |
select {
|
| 82 | 82 |
case err := <-errs: |
| 83 |
- assert.Check(t, err == nil || err == io.EOF) |
|
| 83 |
+ assert.Check(t, err == nil || errors.Is(err, io.EOF)) |
|
| 84 | 84 |
return actions |
| 85 | 85 |
case e := <-messages: |
| 86 | 86 |
actions = append(actions, e.Action) |
| ... | ... |
@@ -4,6 +4,7 @@ package authz |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 | 6 |
"context" |
| 7 |
+ "errors" |
|
| 7 | 8 |
"fmt" |
| 8 | 9 |
"io" |
| 9 | 10 |
"net" |
| ... | ... |
@@ -255,7 +256,7 @@ func TestAuthZPluginAllowEventStream(t *testing.T) {
|
| 255 | 255 |
} |
| 256 | 256 |
} |
| 257 | 257 |
case err := <-errs: |
| 258 |
- if err == io.EOF {
|
|
| 258 |
+ if errors.Is(err, io.EOF) {
|
|
| 259 | 259 |
t.Fatal("premature end of event stream")
|
| 260 | 260 |
} |
| 261 | 261 |
assert.NilError(t, err) |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package bitmap |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"math/rand" |
| 5 | 6 |
"testing" |
| 6 | 7 |
"time" |
| ... | ... |
@@ -677,13 +678,13 @@ func TestSetUnset(t *testing.T) {
|
| 677 | 677 |
t.Fatal(err) |
| 678 | 678 |
} |
| 679 | 679 |
} |
| 680 |
- if _, err := hnd.SetAny(false); err != ErrNoBitAvailable {
|
|
| 680 |
+ if _, err := hnd.SetAny(false); !errors.Is(err, ErrNoBitAvailable) {
|
|
| 681 | 681 |
t.Fatal("Expected error. Got success")
|
| 682 | 682 |
} |
| 683 |
- if _, err := hnd.SetAnyInRange(10, 20, false); err != ErrNoBitAvailable {
|
|
| 683 |
+ if _, err := hnd.SetAnyInRange(10, 20, false); !errors.Is(err, ErrNoBitAvailable) {
|
|
| 684 | 684 |
t.Fatal("Expected error. Got success")
|
| 685 | 685 |
} |
| 686 |
- if err := hnd.Set(50); err != ErrBitAllocated {
|
|
| 686 |
+ if err := hnd.Set(50); !errors.Is(err, ErrBitAllocated) {
|
|
| 687 | 687 |
t.Fatalf("Expected error. Got %v: %s", err, hnd)
|
| 688 | 688 |
} |
| 689 | 689 |
i := uint64(0) |
| ... | ... |
@@ -706,11 +707,11 @@ func TestOffsetSetUnset(t *testing.T) {
|
| 706 | 706 |
} |
| 707 | 707 |
} |
| 708 | 708 |
|
| 709 |
- if _, err := hnd.SetAny(false); err != ErrNoBitAvailable {
|
|
| 709 |
+ if _, err := hnd.SetAny(false); !errors.Is(err, ErrNoBitAvailable) {
|
|
| 710 | 710 |
t.Fatal("Expected error. Got success")
|
| 711 | 711 |
} |
| 712 | 712 |
|
| 713 |
- if _, err := hnd.SetAnyInRange(10, 20, false); err != ErrNoBitAvailable {
|
|
| 713 |
+ if _, err := hnd.SetAnyInRange(10, 20, false); !errors.Is(err, ErrNoBitAvailable) {
|
|
| 714 | 714 |
t.Fatal("Expected error. Got success")
|
| 715 | 715 |
} |
| 716 | 716 |
|
| ... | ... |
@@ -812,7 +813,7 @@ func TestSetInRange(t *testing.T) {
|
| 812 | 812 |
if err == nil {
|
| 813 | 813 |
t.Fatalf("Expected failure. Got success with ordinal:%d", o)
|
| 814 | 814 |
} |
| 815 |
- if err != ErrNoBitAvailable {
|
|
| 815 |
+ if !errors.Is(err, ErrNoBitAvailable) {
|
|
| 816 | 816 |
t.Fatalf("Unexpected error: %v", err)
|
| 817 | 817 |
} |
| 818 | 818 |
|
| ... | ... |
@@ -829,7 +830,7 @@ func TestSetInRange(t *testing.T) {
|
| 829 | 829 |
if err == nil {
|
| 830 | 830 |
t.Fatalf("Expected failure. Got success with ordinal:%d", o)
|
| 831 | 831 |
} |
| 832 |
- if err != ErrNoBitAvailable {
|
|
| 832 |
+ if !errors.Is(err, ErrNoBitAvailable) {
|
|
| 833 | 833 |
t.Fatalf("Unexpected error: %v", err)
|
| 834 | 834 |
} |
| 835 | 835 |
|
| ... | ... |
@@ -844,7 +845,7 @@ func TestSetInRange(t *testing.T) {
|
| 844 | 844 |
if err == nil {
|
| 845 | 845 |
t.Fatalf("Expected failure. Got success with ordinal:%d", o)
|
| 846 | 846 |
} |
| 847 |
- if err != ErrNoBitAvailable {
|
|
| 847 |
+ if !errors.Is(err, ErrNoBitAvailable) {
|
|
| 848 | 848 |
t.Fatalf("Unexpected error: %v", err)
|
| 849 | 849 |
} |
| 850 | 850 |
} |
| ... | ... |
@@ -591,7 +591,7 @@ func (na *cnmNetworkAllocator) allocateVIP(vip *api.Endpoint_VirtualIP) error {
|
| 591 | 591 |
|
| 592 | 592 |
for _, poolID := range localNet.pools {
|
| 593 | 593 |
ip, _, err := ipam.RequestAddress(poolID, addr, opts) |
| 594 |
- if err != nil && err != ipamapi.ErrNoAvailableIPs && err != ipamapi.ErrIPOutOfRange {
|
|
| 594 |
+ if err != nil && !errors.Is(err, ipamapi.ErrNoAvailableIPs) && !errors.Is(err, ipamapi.ErrIPOutOfRange) {
|
|
| 595 | 595 |
return errors.Wrap(err, "could not allocate VIP from IPAM") |
| 596 | 596 |
} |
| 597 | 597 |
|
| ... | ... |
@@ -682,7 +682,7 @@ func (na *cnmNetworkAllocator) allocateNetworkIPs(nAttach *api.NetworkAttachment |
| 682 | 682 |
var err error |
| 683 | 683 |
|
| 684 | 684 |
ip, _, err = ipam.RequestAddress(poolID, addr, opts) |
| 685 |
- if err != nil && err != ipamapi.ErrNoAvailableIPs && err != ipamapi.ErrIPOutOfRange {
|
|
| 685 |
+ if err != nil && !errors.Is(err, ipamapi.ErrNoAvailableIPs) && !errors.Is(err, ipamapi.ErrIPOutOfRange) {
|
|
| 686 | 686 |
return errors.Wrap(err, "could not allocate IP from IPAM") |
| 687 | 687 |
} |
| 688 | 688 |
|
| ... | ... |
@@ -1076,7 +1076,7 @@ func (c *Controller) loadDriver(networkType string) error {
|
| 1076 | 1076 |
} |
| 1077 | 1077 |
|
| 1078 | 1078 |
if err != nil {
|
| 1079 |
- if errors.Cause(err) == plugins.ErrNotFound {
|
|
| 1079 |
+ if errors.Is(err, plugins.ErrNotFound) {
|
|
| 1080 | 1080 |
return types.NotFoundErrorf("%v", err)
|
| 1081 | 1081 |
} |
| 1082 | 1082 |
return err |
| ... | ... |
@@ -1095,7 +1095,7 @@ func (c *Controller) loadIPAMDriver(name string) error {
|
| 1095 | 1095 |
} |
| 1096 | 1096 |
|
| 1097 | 1097 |
if err != nil {
|
| 1098 |
- if errors.Cause(err) == plugins.ErrNotFound {
|
|
| 1098 |
+ if errors.Is(err, plugins.ErrNotFound) {
|
|
| 1099 | 1099 |
return types.NotFoundErrorf("%v", err)
|
| 1100 | 1100 |
} |
| 1101 | 1101 |
return err |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package datastore |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
"sync" |
| 6 | 7 |
|
| ... | ... |
@@ -35,7 +36,7 @@ func (c *cache) kmap(kvObject KVObject) (kvMap, error) {
|
| 35 | 35 |
|
| 36 | 36 |
kvList, err := c.ds.List(keyPrefix) |
| 37 | 37 |
if err != nil {
|
| 38 |
- if err == store.ErrKeyNotFound {
|
|
| 38 |
+ if errors.Is(err, store.ErrKeyNotFound) {
|
|
| 39 | 39 |
// If the store doesn't have anything then there is nothing to |
| 40 | 40 |
// populate in the cache. Just bail out. |
| 41 | 41 |
goto out |
| ... | ... |
@@ -121,7 +121,7 @@ func (ds *Store) PutObjectAtomic(kvObject KVObject) error {
|
| 121 | 121 |
|
| 122 | 122 |
pair, err := ds.store.AtomicPut(Key(kvObject.Key()...), kvObjValue, previous) |
| 123 | 123 |
if err != nil {
|
| 124 |
- if err == store.ErrKeyExists {
|
|
| 124 |
+ if errors.Is(err, store.ErrKeyExists) {
|
|
| 125 | 125 |
return ErrKeyModified |
| 126 | 126 |
} |
| 127 | 127 |
return err |
| ... | ... |
@@ -245,7 +245,7 @@ func (ds *Store) DeleteObjectAtomic(kvObject KVObject) error {
|
| 245 | 245 |
|
| 246 | 246 |
if !kvObject.Skip() {
|
| 247 | 247 |
if err := ds.store.AtomicDelete(Key(kvObject.Key()...), previous); err != nil {
|
| 248 |
- if err == store.ErrKeyExists {
|
|
| 248 |
+ if errors.Is(err, store.ErrKeyExists) {
|
|
| 249 | 249 |
return ErrKeyModified |
| 250 | 250 |
} |
| 251 | 251 |
return err |
| ... | ... |
@@ -956,7 +956,7 @@ func (d *driver) deleteNetwork(nid string) error {
|
| 956 | 956 |
// it's not in d.networks. To prevent the driver's state from getting out of step |
| 957 | 957 |
// with its parent, make sure it's not in the store before reporting that it does |
| 958 | 958 |
// not exist. |
| 959 |
- if err := d.storeDelete(&networkConfiguration{ID: nid}); err != nil && err != datastore.ErrKeyNotFound {
|
|
| 959 |
+ if err := d.storeDelete(&networkConfiguration{ID: nid}); err != nil && !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 960 | 960 |
log.G(context.TODO()).WithFields(log.Fields{
|
| 961 | 961 |
"error": err, |
| 962 | 962 |
"network": nid, |
| ... | ... |
@@ -5,6 +5,7 @@ package bridge |
| 5 | 5 |
import ( |
| 6 | 6 |
"context" |
| 7 | 7 |
"encoding/json" |
| 8 |
+ "errors" |
|
| 8 | 9 |
"fmt" |
| 9 | 10 |
"net" |
| 10 | 11 |
"strings" |
| ... | ... |
@@ -43,12 +44,12 @@ func (d *driver) initStore() error {
|
| 43 | 43 |
|
| 44 | 44 |
func (d *driver) populateNetworks() error {
|
| 45 | 45 |
kvol, err := d.store.List(&networkConfiguration{})
|
| 46 |
- if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 47 |
- return fmt.Errorf("failed to get bridge network configurations from store: %v", err)
|
|
| 46 |
+ if err != nil && !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 47 |
+ return fmt.Errorf("failed to get bridge network configurations from store: %w", err)
|
|
| 48 | 48 |
} |
| 49 | 49 |
|
| 50 | 50 |
// It's normal for network configuration state to be empty. Just return. |
| 51 |
- if err == datastore.ErrKeyNotFound {
|
|
| 51 |
+ if errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 52 | 52 |
return nil |
| 53 | 53 |
} |
| 54 | 54 |
|
| ... | ... |
@@ -68,11 +69,11 @@ func (d *driver) populateNetworks() error {
|
| 68 | 68 |
|
| 69 | 69 |
func (d *driver) populateEndpoints() error {
|
| 70 | 70 |
kvol, err := d.store.List(&bridgeEndpoint{})
|
| 71 |
- if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 72 |
- return fmt.Errorf("failed to get bridge endpoints from store: %v", err)
|
|
| 71 |
+ if err != nil && !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 72 |
+ return fmt.Errorf("failed to get bridge endpoints from store: %w", err)
|
|
| 73 | 73 |
} |
| 74 | 74 |
|
| 75 |
- if err == datastore.ErrKeyNotFound {
|
|
| 75 |
+ if errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 76 | 76 |
return nil |
| 77 | 77 |
} |
| 78 | 78 |
|
| ... | ... |
@@ -5,6 +5,7 @@ package ipvlan |
| 5 | 5 |
import ( |
| 6 | 6 |
"context" |
| 7 | 7 |
"encoding/json" |
| 8 |
+ "errors" |
|
| 8 | 9 |
"fmt" |
| 9 | 10 |
"net" |
| 10 | 11 |
|
| ... | ... |
@@ -56,11 +57,11 @@ func (d *driver) initStore() error {
|
| 56 | 56 |
// populateNetworks is invoked at driver init to recreate persistently stored networks |
| 57 | 57 |
func (d *driver) populateNetworks() error {
|
| 58 | 58 |
kvol, err := d.store.List(&configuration{})
|
| 59 |
- if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 60 |
- return fmt.Errorf("failed to get ipvlan network configurations from store: %v", err)
|
|
| 59 |
+ if err != nil && !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 60 |
+ return fmt.Errorf("failed to get ipvlan network configurations from store: %w", err)
|
|
| 61 | 61 |
} |
| 62 | 62 |
// If empty it simply means no ipvlan networks have been created yet |
| 63 |
- if err == datastore.ErrKeyNotFound {
|
|
| 63 |
+ if errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 64 | 64 |
return nil |
| 65 | 65 |
} |
| 66 | 66 |
for _, kvo := range kvol {
|
| ... | ... |
@@ -75,11 +76,11 @@ func (d *driver) populateNetworks() error {
|
| 75 | 75 |
|
| 76 | 76 |
func (d *driver) populateEndpoints() error {
|
| 77 | 77 |
kvol, err := d.store.List(&endpoint{})
|
| 78 |
- if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 79 |
- return fmt.Errorf("failed to get ipvlan endpoints from store: %v", err)
|
|
| 78 |
+ if err != nil && !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 79 |
+ return fmt.Errorf("failed to get ipvlan endpoints from store: %w", err)
|
|
| 80 | 80 |
} |
| 81 | 81 |
|
| 82 |
- if err == datastore.ErrKeyNotFound {
|
|
| 82 |
+ if errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 83 | 83 |
return nil |
| 84 | 84 |
} |
| 85 | 85 |
|
| ... | ... |
@@ -5,6 +5,7 @@ package macvlan |
| 5 | 5 |
import ( |
| 6 | 6 |
"context" |
| 7 | 7 |
"encoding/json" |
| 8 |
+ "errors" |
|
| 8 | 9 |
"fmt" |
| 9 | 10 |
"net" |
| 10 | 11 |
|
| ... | ... |
@@ -55,11 +56,11 @@ func (d *driver) initStore() error {
|
| 55 | 55 |
// populateNetworks is invoked at driver init to recreate persistently stored networks |
| 56 | 56 |
func (d *driver) populateNetworks() error {
|
| 57 | 57 |
kvol, err := d.store.List(&configuration{})
|
| 58 |
- if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 59 |
- return fmt.Errorf("failed to get macvlan network configurations from store: %v", err)
|
|
| 58 |
+ if err != nil && !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 59 |
+ return fmt.Errorf("failed to get macvlan network configurations from store: %w", err)
|
|
| 60 | 60 |
} |
| 61 | 61 |
// If empty it simply means no macvlan networks have been created yet |
| 62 |
- if err == datastore.ErrKeyNotFound {
|
|
| 62 |
+ if errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 63 | 63 |
return nil |
| 64 | 64 |
} |
| 65 | 65 |
for _, kvo := range kvol {
|
| ... | ... |
@@ -74,11 +75,11 @@ func (d *driver) populateNetworks() error {
|
| 74 | 74 |
|
| 75 | 75 |
func (d *driver) populateEndpoints() error {
|
| 76 | 76 |
kvol, err := d.store.List(&endpoint{})
|
| 77 |
- if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 78 |
- return fmt.Errorf("failed to get macvlan endpoints from store: %v", err)
|
|
| 77 |
+ if err != nil && !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 78 |
+ return fmt.Errorf("failed to get macvlan endpoints from store: %w", err)
|
|
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
- if err == datastore.ErrKeyNotFound {
|
|
| 81 |
+ if errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 82 | 82 |
return nil |
| 83 | 83 |
} |
| 84 | 84 |
|
| ... | ... |
@@ -7,6 +7,7 @@ import ( |
| 7 | 7 |
"context" |
| 8 | 8 |
"encoding/binary" |
| 9 | 9 |
"encoding/hex" |
| 10 |
+ "errors" |
|
| 10 | 11 |
"fmt" |
| 11 | 12 |
"hash/fnv" |
| 12 | 13 |
"net" |
| ... | ... |
@@ -431,10 +432,10 @@ func programSP(fSA *netlink.XfrmState, rSA *netlink.XfrmState, add bool) error {
|
| 431 | 431 |
|
| 432 | 432 |
func saExists(sa *netlink.XfrmState) (bool, error) {
|
| 433 | 433 |
_, err := ns.NlHandle().XfrmStateGet(sa) |
| 434 |
- switch err {
|
|
| 435 |
- case nil: |
|
| 434 |
+ switch {
|
|
| 435 |
+ case err == nil: |
|
| 436 | 436 |
return true, nil |
| 437 |
- case syscall.ESRCH: |
|
| 437 |
+ case errors.Is(err, syscall.ESRCH): |
|
| 438 | 438 |
return false, nil |
| 439 | 439 |
default: |
| 440 | 440 |
err = fmt.Errorf("Error while checking for SA existence: %v", err)
|
| ... | ... |
@@ -445,10 +446,10 @@ func saExists(sa *netlink.XfrmState) (bool, error) {
|
| 445 | 445 |
|
| 446 | 446 |
func spExists(sp *netlink.XfrmPolicy) (bool, error) {
|
| 447 | 447 |
_, err := ns.NlHandle().XfrmPolicyGet(sp) |
| 448 |
- switch err {
|
|
| 449 |
- case nil: |
|
| 448 |
+ switch {
|
|
| 449 |
+ case err == nil: |
|
| 450 | 450 |
return true, nil |
| 451 |
- case syscall.ENOENT: |
|
| 451 |
+ case errors.Is(err, syscall.ENOENT): |
|
| 452 | 452 |
return false, nil |
| 453 | 453 |
default: |
| 454 | 454 |
err = fmt.Errorf("Error while checking for SP existence: %v", err)
|
| ... | ... |
@@ -28,7 +28,7 @@ func handle(t *testing.T, mux *http.ServeMux, method string, h func(map[string]i |
| 28 | 28 |
mux.HandleFunc(fmt.Sprintf("/%s.%s", driverapi.NetworkPluginEndpointType, method), func(w http.ResponseWriter, r *http.Request) {
|
| 29 | 29 |
var ask map[string]interface{}
|
| 30 | 30 |
err := json.NewDecoder(r.Body).Decode(&ask) |
| 31 |
- if err != nil && err != io.EOF {
|
|
| 31 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 32 | 32 |
t.Fatal(err) |
| 33 | 33 |
} |
| 34 | 34 |
answer := h(ask) |
| ... | ... |
@@ -6,6 +6,7 @@ package libnetwork |
| 6 | 6 |
import ( |
| 7 | 7 |
"context" |
| 8 | 8 |
"encoding/json" |
| 9 |
+ "errors" |
|
| 9 | 10 |
"fmt" |
| 10 | 11 |
"net" |
| 11 | 12 |
"net/netip" |
| ... | ... |
@@ -1334,7 +1335,7 @@ func (ep *Endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
|
| 1334 | 1334 |
ep.mu.Unlock() |
| 1335 | 1335 |
return nil |
| 1336 | 1336 |
} |
| 1337 |
- if err != ipamapi.ErrNoAvailableIPs || progAdd != nil {
|
|
| 1337 |
+ if !errors.Is(err, ipamapi.ErrNoAvailableIPs) || progAdd != nil {
|
|
| 1338 | 1338 |
return err |
| 1339 | 1339 |
} |
| 1340 | 1340 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package defaultipam |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"flag" |
| 6 | 7 |
"fmt" |
| 7 | 8 |
"math/rand" |
| ... | ... |
@@ -404,7 +405,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
|
| 404 | 404 |
ip = c |
| 405 | 405 |
} |
| 406 | 406 |
} |
| 407 |
- if err != ipamapi.ErrNoAvailableIPs {
|
|
| 407 |
+ if !errors.Is(err, ipamapi.ErrNoAvailableIPs) {
|
|
| 408 | 408 |
t.Fatal(err) |
| 409 | 409 |
} |
| 410 | 410 |
if !types.CompareIPNet(expected, ip) {
|
| ... | ... |
@@ -436,7 +437,7 @@ func TestRequestReleaseAddressFromSubPool(t *testing.T) {
|
| 436 | 436 |
ip = c |
| 437 | 437 |
} |
| 438 | 438 |
} |
| 439 |
- if err != ipamapi.ErrNoAvailableIPs {
|
|
| 439 |
+ if !errors.Is(err, ipamapi.ErrNoAvailableIPs) {
|
|
| 440 | 440 |
t.Fatal(err) |
| 441 | 441 |
} |
| 442 | 442 |
if !types.CompareIPNet(expected, ip) {
|
| ... | ... |
@@ -528,7 +529,7 @@ func TestSerializeRequestReleaseAddressFromSubPool(t *testing.T) {
|
| 528 | 528 |
ip = c |
| 529 | 529 |
} |
| 530 | 530 |
} |
| 531 |
- if err != ipamapi.ErrNoAvailableIPs {
|
|
| 531 |
+ if !errors.Is(err, ipamapi.ErrNoAvailableIPs) {
|
|
| 532 | 532 |
t.Fatal(err) |
| 533 | 533 |
} |
| 534 | 534 |
if !types.CompareIPNet(expected, ip) {
|
| ... | ... |
@@ -560,7 +561,7 @@ func TestSerializeRequestReleaseAddressFromSubPool(t *testing.T) {
|
| 560 | 560 |
ip = c |
| 561 | 561 |
} |
| 562 | 562 |
} |
| 563 |
- if err != ipamapi.ErrNoAvailableIPs {
|
|
| 563 |
+ if !errors.Is(err, ipamapi.ErrNoAvailableIPs) {
|
|
| 564 | 564 |
t.Fatal(err) |
| 565 | 565 |
} |
| 566 | 566 |
if !types.CompareIPNet(expected, ip) {
|
| ... | ... |
@@ -853,7 +854,7 @@ func TestUnusualSubnets(t *testing.T) {
|
| 853 | 853 |
|
| 854 | 854 |
for _, outside := range outsideTheRangeAddresses {
|
| 855 | 855 |
_, _, errx := allocator.RequestAddress(alloc.PoolID, net.ParseIP(outside.address), nil) |
| 856 |
- if errx != ipamapi.ErrIPOutOfRange {
|
|
| 856 |
+ if !errors.Is(errx, ipamapi.ErrIPOutOfRange) {
|
|
| 857 | 857 |
t.Fatalf("Address %s failed to throw expected error: %s", outside.address, errx.Error())
|
| 858 | 858 |
} |
| 859 | 859 |
} |
| ... | ... |
@@ -873,7 +874,7 @@ func TestUnusualSubnets(t *testing.T) {
|
| 873 | 873 |
} |
| 874 | 874 |
|
| 875 | 875 |
_, _, err = allocator.RequestAddress(alloc.PoolID, nil, nil) |
| 876 |
- if err != ipamapi.ErrNoAvailableIPs {
|
|
| 876 |
+ if !errors.Is(err, ipamapi.ErrNoAvailableIPs) {
|
|
| 877 | 877 |
t.Fatal("Did not get expected error when pool is exhausted.")
|
| 878 | 878 |
} |
| 879 | 879 |
} |
| ... | ... |
@@ -890,7 +891,7 @@ func TestRelease(t *testing.T) {
|
| 890 | 890 |
} |
| 891 | 891 |
|
| 892 | 892 |
// Allocate all addresses |
| 893 |
- for err != ipamapi.ErrNoAvailableIPs {
|
|
| 893 |
+ for !errors.Is(err, ipamapi.ErrNoAvailableIPs) {
|
|
| 894 | 894 |
_, _, err = a.RequestAddress(alloc.PoolID, nil, nil) |
| 895 | 895 |
} |
| 896 | 896 |
|
| ... | ... |
@@ -948,7 +949,7 @@ func assertGetAddress(t *testing.T, subnet string) {
|
| 948 | 948 |
|
| 949 | 949 |
start := time.Now() |
| 950 | 950 |
run := 0 |
| 951 |
- for err != ipamapi.ErrNoAvailableIPs {
|
|
| 951 |
+ for !errors.Is(err, ipamapi.ErrNoAvailableIPs) {
|
|
| 952 | 952 |
_, err = getAddress(sub, bm, netip.Addr{}, netip.Prefix{}, false)
|
| 953 | 953 |
run++ |
| 954 | 954 |
} |
| ... | ... |
@@ -997,7 +998,7 @@ func assertNRequests(t *testing.T, subnet string, numReq int, lastExpectedIP str |
| 997 | 997 |
|
| 998 | 998 |
func benchmarkRequest(b *testing.B, a *Allocator, subnet string) {
|
| 999 | 999 |
alloc, err := a.RequestPool(ipamapi.PoolRequest{AddressSpace: localAddressSpace, Pool: subnet})
|
| 1000 |
- for err != ipamapi.ErrNoAvailableIPs {
|
|
| 1000 |
+ for !errors.Is(err, ipamapi.ErrNoAvailableIPs) {
|
|
| 1001 | 1001 |
_, _, err = a.RequestAddress(alloc.PoolID, nil, nil) |
| 1002 | 1002 |
} |
| 1003 | 1003 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package remote |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"encoding/json" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"fmt" |
| 6 | 7 |
"io" |
| 7 | 8 |
"net" |
| ... | ... |
@@ -22,7 +23,7 @@ func handle(t *testing.T, mux *http.ServeMux, method string, h func(map[string]i |
| 22 | 22 |
mux.HandleFunc(fmt.Sprintf("/%s.%s", ipamapi.PluginEndpointType, method), func(w http.ResponseWriter, r *http.Request) {
|
| 23 | 23 |
var ask map[string]interface{}
|
| 24 | 24 |
err := json.NewDecoder(r.Body).Decode(&ask) |
| 25 |
- if err != nil && err != io.EOF {
|
|
| 25 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 26 | 26 |
t.Fatal(err) |
| 27 | 27 |
} |
| 28 | 28 |
answer := h(ask) |
| ... | ... |
@@ -1619,7 +1619,7 @@ func (n *Network) ipamAllocateVersion(ipVer int, ipam ipamapi.Ipam) error {
|
| 1619 | 1619 |
return types.ForbiddenErrorf("auxiliary address: (%s:%s) must belong to the master pool: %s", k, v, d.Pool)
|
| 1620 | 1620 |
} |
| 1621 | 1621 |
// Attempt reservation in the container addressable pool, silent the error if address does not belong to that pool |
| 1622 |
- if d.IPAMData.AuxAddresses[k], _, err = ipam.RequestAddress(d.PoolID, ip, nil); err != nil && err != ipamapi.ErrIPOutOfRange {
|
|
| 1622 |
+ if d.IPAMData.AuxAddresses[k], _, err = ipam.RequestAddress(d.PoolID, ip, nil); err != nil && !errors.Is(err, ipamapi.ErrIPOutOfRange) {
|
|
| 1623 | 1623 |
return types.InternalErrorf("failed to allocate secondary ip address (%s:%s): %v", k, v, err)
|
| 1624 | 1624 |
} |
| 1625 | 1625 |
} |
| ... | ... |
@@ -1673,7 +1673,7 @@ func (n *Network) ipamReleaseVersion(ipVer int, ipam ipamapi.Ipam) {
|
| 1673 | 1673 |
if d.IPAMData.AuxAddresses != nil {
|
| 1674 | 1674 |
for k, nw := range d.IPAMData.AuxAddresses {
|
| 1675 | 1675 |
if d.Pool.Contains(nw.IP) {
|
| 1676 |
- if err := ipam.ReleaseAddress(d.PoolID, nw.IP); err != nil && err != ipamapi.ErrIPOutOfRange {
|
|
| 1676 |
+ if err := ipam.ReleaseAddress(d.PoolID, nw.IP); err != nil && !errors.Is(err, ipamapi.ErrIPOutOfRange) {
|
|
| 1677 | 1677 |
log.G(context.TODO()).Warnf("Failed to release secondary ip address %s (%v) on delete of network %s (%s): %v", k, nw.IP, n.Name(), n.ID(), err)
|
| 1678 | 1678 |
} |
| 1679 | 1679 |
} |
| ... | ... |
@@ -93,7 +93,7 @@ func TestReleaseUnreadledPort(t *testing.T) {
|
| 93 | 93 |
func TestUnknowProtocol(t *testing.T) {
|
| 94 | 94 |
p := newInstance() |
| 95 | 95 |
|
| 96 |
- if _, err := p.RequestPort(net.IPv4zero, "tcpp", 0); err != errUnknownProtocol {
|
|
| 96 |
+ if _, err := p.RequestPort(net.IPv4zero, "tcpp", 0); !errors.Is(err, errUnknownProtocol) {
|
|
| 97 | 97 |
t.Fatalf("Expected error %s got %s", errUnknownProtocol, err)
|
| 98 | 98 |
} |
| 99 | 99 |
} |
| ... | ... |
@@ -112,7 +112,7 @@ func TestAllocateAllPorts(t *testing.T) {
|
| 112 | 112 |
} |
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 |
- if _, err := p.RequestPort(net.IPv4zero, "tcp", 0); err != errAllPortsAllocated {
|
|
| 115 |
+ if _, err := p.RequestPort(net.IPv4zero, "tcp", 0); !errors.Is(err, errAllPortsAllocated) {
|
|
| 116 | 116 |
t.Fatalf("Expected error %s got %s", errAllPortsAllocated, err)
|
| 117 | 117 |
} |
| 118 | 118 |
|
| ... | ... |
@@ -281,7 +281,7 @@ func TestPortAllocationWithCustomRange(t *testing.T) {
|
| 281 | 281 |
t.Fatal("Allocated the same port from a custom range")
|
| 282 | 282 |
} |
| 283 | 283 |
// request 3rd port from the range of 2 |
| 284 |
- if _, err := p.RequestPortInRange(net.IPv4zero, "tcp", start, end); err != errAllPortsAllocated {
|
|
| 284 |
+ if _, err := p.RequestPortInRange(net.IPv4zero, "tcp", start, end); !errors.Is(err, errAllPortsAllocated) {
|
|
| 285 | 285 |
t.Fatalf("Expected error %s got %s", errAllPortsAllocated, err)
|
| 286 | 286 |
} |
| 287 | 287 |
} |
| ... | ... |
@@ -125,7 +125,7 @@ func waitForLocalDNSServer(t *testing.T) {
|
| 125 | 125 |
if err != nil {
|
| 126 | 126 |
if oerr, ok := err.(*net.OpError); ok {
|
| 127 | 127 |
// server is probably initializing |
| 128 |
- if oerr.Err == syscall.ECONNREFUSED {
|
|
| 128 |
+ if errors.Is(oerr.Err, syscall.ECONNREFUSED) {
|
|
| 129 | 129 |
continue |
| 130 | 130 |
} |
| 131 | 131 |
} else {
|
| ... | ... |
@@ -3,6 +3,7 @@ package libnetwork |
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 | 5 |
"encoding/json" |
| 6 |
+ "errors" |
|
| 6 | 7 |
"fmt" |
| 7 | 8 |
|
| 8 | 9 |
"github.com/containerd/log" |
| ... | ... |
@@ -147,7 +148,7 @@ retry: |
| 147 | 147 |
} |
| 148 | 148 |
|
| 149 | 149 |
err := sb.controller.updateToStore(ctx, sbs) |
| 150 |
- if err == datastore.ErrKeyModified {
|
|
| 150 |
+ if errors.Is(err, datastore.ErrKeyModified) {
|
|
| 151 | 151 |
// When we get ErrKeyModified it is sufficient to just |
| 152 | 152 |
// go back and retry. No need to get the object from |
| 153 | 153 |
// the store because we always regenerate the store |
| ... | ... |
@@ -171,7 +172,7 @@ func (sb *Sandbox) storeDelete() error {
|
| 171 | 171 |
func (c *Controller) sandboxRestore(activeSandboxes map[string]interface{}) error {
|
| 172 | 172 |
sandboxStates, err := c.store.List(&sbState{c: c})
|
| 173 | 173 |
if err != nil {
|
| 174 |
- if err == datastore.ErrKeyNotFound {
|
|
| 174 |
+ if errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 175 | 175 |
// It's normal for no sandboxes to be found. Just bail out. |
| 176 | 176 |
return nil |
| 177 | 177 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package libnetwork |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"fmt" |
| 6 | 7 |
"io" |
| 7 | 8 |
"net" |
| ... | ... |
@@ -138,7 +139,7 @@ func (n *Network) addLBBackend(ip net.IP, lb *loadBalancer) {
|
| 138 | 138 |
return |
| 139 | 139 |
} |
| 140 | 140 |
|
| 141 |
- if err := i.NewService(s); err != nil && err != syscall.EEXIST {
|
|
| 141 |
+ if err := i.NewService(s); err != nil && !errors.Is(err, syscall.EEXIST) {
|
|
| 142 | 142 |
log.G(context.TODO()).Errorf("Failed to create a new service for vip %s fwmark %d in sbox %.7s (%.7s): %v", lb.vip, lb.fwMark, sb.ID(), sb.ContainerID(), err)
|
| 143 | 143 |
return |
| 144 | 144 |
} |
| ... | ... |
@@ -158,7 +159,7 @@ func (n *Network) addLBBackend(ip net.IP, lb *loadBalancer) {
|
| 158 | 158 |
Weight: 1, |
| 159 | 159 |
ConnectionFlags: flags, |
| 160 | 160 |
}) |
| 161 |
- if err != nil && err != syscall.EEXIST {
|
|
| 161 |
+ if err != nil && !errors.Is(err, syscall.EEXIST) {
|
|
| 162 | 162 |
log.G(context.TODO()).Errorf("Failed to create real server %s for vip %s fwmark %d in sbox %.7s (%.7s): %v", ip, lb.vip, lb.fwMark, sb.ID(), sb.ContainerID(), err)
|
| 163 | 163 |
} |
| 164 | 164 |
|
| ... | ... |
@@ -208,19 +209,19 @@ func (n *Network) rmLBBackend(ip net.IP, lb *loadBalancer, rmService bool, fullR |
| 208 | 208 |
} |
| 209 | 209 |
|
| 210 | 210 |
if fullRemove {
|
| 211 |
- if err := i.DelDestination(s, d); err != nil && err != syscall.ENOENT {
|
|
| 211 |
+ if err := i.DelDestination(s, d); err != nil && !errors.Is(err, syscall.ENOENT) {
|
|
| 212 | 212 |
log.G(context.TODO()).Errorf("Failed to delete real server %s for vip %s fwmark %d in sbox %.7s (%.7s): %v", ip, lb.vip, lb.fwMark, sb.ID(), sb.ContainerID(), err)
|
| 213 | 213 |
} |
| 214 | 214 |
} else {
|
| 215 | 215 |
d.Weight = 0 |
| 216 |
- if err := i.UpdateDestination(s, d); err != nil && err != syscall.ENOENT {
|
|
| 216 |
+ if err := i.UpdateDestination(s, d); err != nil && !errors.Is(err, syscall.ENOENT) {
|
|
| 217 | 217 |
log.G(context.TODO()).Errorf("Failed to set LB weight of real server %s to 0 for vip %s fwmark %d in sbox %.7s (%.7s): %v", ip, lb.vip, lb.fwMark, sb.ID(), sb.ContainerID(), err)
|
| 218 | 218 |
} |
| 219 | 219 |
} |
| 220 | 220 |
|
| 221 | 221 |
if rmService {
|
| 222 | 222 |
s.SchedName = ipvs.RoundRobin |
| 223 |
- if err := i.DelService(s); err != nil && err != syscall.ENOENT {
|
|
| 223 |
+ if err := i.DelService(s); err != nil && !errors.Is(err, syscall.ENOENT) {
|
|
| 224 | 224 |
log.G(context.TODO()).Errorf("Failed to delete service for vip %s fwmark %d in sbox %.7s (%.7s): %v", lb.vip, lb.fwMark, sb.ID(), sb.ContainerID(), err)
|
| 225 | 225 |
} |
| 226 | 226 |
|
| ... | ... |
@@ -2,6 +2,7 @@ package libnetwork |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"fmt" |
| 6 | 7 |
|
| 7 | 8 |
"github.com/containerd/log" |
| ... | ... |
@@ -23,7 +24,7 @@ func (c *Controller) getNetworks() ([]*Network, error) {
|
| 23 | 23 |
var nl []*Network |
| 24 | 24 |
|
| 25 | 25 |
kvol, err := c.store.List(&Network{ctrlr: c})
|
| 26 |
- if err != nil && err != datastore.ErrKeyNotFound {
|
|
| 26 |
+ if err != nil && !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 27 | 27 |
return nil, fmt.Errorf("failed to get networks: %w", err)
|
| 28 | 28 |
} |
| 29 | 29 |
|
| ... | ... |
@@ -45,7 +46,7 @@ func (c *Controller) getNetworksFromStore(ctx context.Context) []*Network { // F
|
| 45 | 45 |
|
| 46 | 46 |
kvol, err := c.store.List(&Network{ctrlr: c})
|
| 47 | 47 |
if err != nil {
|
| 48 |
- if err != datastore.ErrKeyNotFound {
|
|
| 48 |
+ if !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 49 | 49 |
log.G(ctx).Debugf("failed to get networks from store: %v", err)
|
| 50 | 50 |
} |
| 51 | 51 |
return nil |
| ... | ... |
@@ -80,7 +81,7 @@ func (n *Network) getEndpointsFromStore() ([]*Endpoint, error) {
|
| 80 | 80 |
|
| 81 | 81 |
kvol, err := n.getController().store.List(&Endpoint{network: n})
|
| 82 | 82 |
if err != nil {
|
| 83 |
- if err != datastore.ErrKeyNotFound {
|
|
| 83 |
+ if !errors.Is(err, datastore.ErrKeyNotFound) {
|
|
| 84 | 84 |
return nil, fmt.Errorf("failed to get endpoints for network %s: %w",
|
| 85 | 85 |
n.Name(), err) |
| 86 | 86 |
} |
| ... | ... |
@@ -101,7 +102,7 @@ func (c *Controller) updateToStore(ctx context.Context, kvObject datastore.KVObj |
| 101 | 101 |
defer span.End() |
| 102 | 102 |
|
| 103 | 103 |
if err := c.store.PutObjectAtomic(kvObject); err != nil {
|
| 104 |
- if err == datastore.ErrKeyModified {
|
|
| 104 |
+ if errors.Is(err, datastore.ErrKeyModified) {
|
|
| 105 | 105 |
return err |
| 106 | 106 |
} |
| 107 | 107 |
return fmt.Errorf("failed to update store for object type %T: %v", kvObject, err)
|
| ... | ... |
@@ -113,7 +114,7 @@ func (c *Controller) updateToStore(ctx context.Context, kvObject datastore.KVObj |
| 113 | 113 |
func (c *Controller) deleteFromStore(kvObject datastore.KVObject) error {
|
| 114 | 114 |
retry: |
| 115 | 115 |
if err := c.store.DeleteObjectAtomic(kvObject); err != nil {
|
| 116 |
- if err == datastore.ErrKeyModified {
|
|
| 116 |
+ if errors.Is(err, datastore.ErrKeyModified) {
|
|
| 117 | 117 |
if err := c.store.GetObject(kvObject); err != nil {
|
| 118 | 118 |
return fmt.Errorf("could not update the kvobject to latest when trying to delete: %v", err)
|
| 119 | 119 |
} |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package oci |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
"os" |
| 6 | 7 |
"path/filepath" |
| ... | ... |
@@ -40,7 +41,7 @@ func DevicesFromPath(pathOnHost, pathInContainer, cgroupPermissions string) (dev |
| 40 | 40 |
|
| 41 | 41 |
// if the device is not a device node |
| 42 | 42 |
// try to see if it's a directory holding many devices |
| 43 |
- if err == coci.ErrNotADevice {
|
|
| 43 |
+ if errors.Is(err, coci.ErrNotADevice) {
|
|
| 44 | 44 |
// check if it is a directory |
| 45 | 45 |
if src, e := os.Stat(resolvedPathOnHost); e == nil && src.IsDir() {
|
| 46 | 46 |
// mount the internal devices recursively |
| ... | ... |
@@ -46,7 +46,7 @@ func TestCancelReadCloser(t *testing.T) {
|
| 46 | 46 |
for {
|
| 47 | 47 |
var buf [128]byte |
| 48 | 48 |
_, err := crc.Read(buf[:]) |
| 49 |
- if err == context.DeadlineExceeded {
|
|
| 49 |
+ if errors.Is(err, context.DeadlineExceeded) {
|
|
| 50 | 50 |
break |
| 51 | 51 |
} else if err != nil {
|
| 52 | 52 |
t.Fatalf("got unexpected error: %v", err)
|
| ... | ... |
@@ -4,6 +4,7 @@ package process |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 | 6 |
"bytes" |
| 7 |
+ "errors" |
|
| 7 | 8 |
"fmt" |
| 8 | 9 |
"os" |
| 9 | 10 |
"path/filepath" |
| ... | ... |
@@ -33,7 +34,7 @@ func Alive(pid int) bool {
|
| 33 | 33 |
|
| 34 | 34 |
// Either the PID was found (no error) or we get an EPERM, which means |
| 35 | 35 |
// the PID exists, but we don't have permissions to signal it. |
| 36 |
- return err == nil || err == unix.EPERM |
|
| 36 |
+ return err == nil || errors.Is(err, unix.EPERM) |
|
| 37 | 37 |
default: |
| 38 | 38 |
_, err := os.Stat(filepath.Join("/proc", strconv.Itoa(pid)))
|
| 39 | 39 |
return err == nil |
| ... | ... |
@@ -51,7 +52,7 @@ func Kill(pid int) error {
|
| 51 | 51 |
return fmt.Errorf("invalid PID (%d): only positive PIDs are allowed", pid)
|
| 52 | 52 |
} |
| 53 | 53 |
err := unix.Kill(pid, unix.SIGKILL) |
| 54 |
- if err != nil && err != unix.ESRCH {
|
|
| 54 |
+ if err != nil && !errors.Is(err, unix.ESRCH) {
|
|
| 55 | 55 |
return err |
| 56 | 56 |
} |
| 57 | 57 |
return nil |
| ... | ... |
@@ -107,7 +107,7 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, _ error) {
|
| 107 | 107 |
var nr2 int |
| 108 | 108 |
nr2, err = src.Read(buf[nr:]) |
| 109 | 109 |
nr += nr2 |
| 110 |
- if err == io.EOF {
|
|
| 110 |
+ if errors.Is(err, io.EOF) {
|
|
| 111 | 111 |
if nr < stdWriterPrefixLen {
|
| 112 | 112 |
return written, nil |
| 113 | 113 |
} |
| ... | ... |
@@ -153,7 +153,7 @@ func StdCopy(dstout, dsterr io.Writer, src io.Reader) (written int64, _ error) {
|
| 153 | 153 |
var nr2 int |
| 154 | 154 |
nr2, err = src.Read(buf[nr:]) |
| 155 | 155 |
nr += nr2 |
| 156 |
- if err == io.EOF {
|
|
| 156 |
+ if errors.Is(err, io.EOF) {
|
|
| 157 | 157 |
if nr < frameSize+stdWriterPrefixLen {
|
| 158 | 158 |
return written, nil |
| 159 | 159 |
} |
| ... | ... |
@@ -67,7 +67,7 @@ func TestWriteWithWriterError(t *testing.T) {
|
| 67 | 67 |
}, Stdout) |
| 68 | 68 |
data := []byte("This won't get written, sigh")
|
| 69 | 69 |
n, err := writer.Write(data) |
| 70 |
- if err != expectedError {
|
|
| 70 |
+ if !errors.Is(err, expectedError) {
|
|
| 71 | 71 |
t.Fatalf("Didn't get expected error.")
|
| 72 | 72 |
} |
| 73 | 73 |
if n != expectedReturnedBytes {
|
| ... | ... |
@@ -139,7 +139,7 @@ func TestStdCopyReturnsErrorReadingHeader(t *testing.T) {
|
| 139 | 139 |
if written != 0 {
|
| 140 | 140 |
t.Fatalf("Expected 0 bytes read, got %d", written)
|
| 141 | 141 |
} |
| 142 |
- if err != expectedError {
|
|
| 142 |
+ if !errors.Is(err, expectedError) {
|
|
| 143 | 143 |
t.Fatalf("Didn't get expected error")
|
| 144 | 144 |
} |
| 145 | 145 |
} |
| ... | ... |
@@ -162,7 +162,7 @@ func TestStdCopyReturnsErrorReadingFrame(t *testing.T) {
|
| 162 | 162 |
if written != 0 {
|
| 163 | 163 |
t.Fatalf("Expected 0 bytes read, got %d", written)
|
| 164 | 164 |
} |
| 165 |
- if err != expectedError {
|
|
| 165 |
+ if !errors.Is(err, expectedError) {
|
|
| 166 | 166 |
t.Fatalf("Didn't get expected error")
|
| 167 | 167 |
} |
| 168 | 168 |
} |
| ... | ... |
@@ -226,7 +226,7 @@ func TestStdCopyReturnsWriteErrors(t *testing.T) {
|
| 226 | 226 |
if written != 0 {
|
| 227 | 227 |
t.Fatalf("StdCopy should have written 0, but has written %d", written)
|
| 228 | 228 |
} |
| 229 |
- if err != expectedError {
|
|
| 229 |
+ if !errors.Is(err, expectedError) {
|
|
| 230 | 230 |
t.Fatalf("Didn't get expected error, got %v", err)
|
| 231 | 231 |
} |
| 232 | 232 |
} |
| ... | ... |
@@ -244,7 +244,7 @@ func TestStdCopyDetectsNotFullyWrittenFrames(t *testing.T) {
|
| 244 | 244 |
if written != 0 {
|
| 245 | 245 |
t.Fatalf("StdCopy should have return 0 written bytes, but returned %d", written)
|
| 246 | 246 |
} |
| 247 |
- if err != io.ErrShortWrite {
|
|
| 247 |
+ if !errors.Is(err, io.ErrShortWrite) {
|
|
| 248 | 248 |
t.Fatalf("Didn't get expected io.ErrShortWrite error")
|
| 249 | 249 |
} |
| 250 | 250 |
} |
| ... | ... |
@@ -3,6 +3,7 @@ |
| 3 | 3 |
package system |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
+ "errors" |
|
| 6 | 7 |
"syscall" |
| 7 | 8 |
|
| 8 | 9 |
"golang.org/x/sys/unix" |
| ... | ... |
@@ -16,7 +17,7 @@ func LUtimesNano(path string, ts []syscall.Timespec) error {
|
| 16 | 16 |
unix.NsecToTimespec(syscall.TimespecToNsec(ts[1])), |
| 17 | 17 |
} |
| 18 | 18 |
err := unix.UtimesNanoAt(unix.AT_FDCWD, path, uts, unix.AT_SYMLINK_NOFOLLOW) |
| 19 |
- if err != nil && err != unix.ENOSYS {
|
|
| 19 |
+ if err != nil && !errors.Is(err, unix.ENOSYS) {
|
|
| 20 | 20 |
return err |
| 21 | 21 |
} |
| 22 | 22 |
|
| ... | ... |
@@ -1,6 +1,8 @@ |
| 1 | 1 |
package system |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 5 |
+ |
|
| 4 | 6 |
"golang.org/x/sys/unix" |
| 5 | 7 |
) |
| 6 | 8 |
|
| ... | ... |
@@ -16,7 +18,7 @@ func Lgetxattr(path string, attr string) ([]byte, error) {
|
| 16 | 16 |
dest := make([]byte, 128) |
| 17 | 17 |
sz, errno := unix.Lgetxattr(path, attr, dest) |
| 18 | 18 |
|
| 19 |
- for errno == unix.ERANGE {
|
|
| 19 |
+ for errors.Is(errno, unix.ERANGE) {
|
|
| 20 | 20 |
// Buffer too small, use zero-sized buffer to get the actual size |
| 21 | 21 |
sz, errno = unix.Lgetxattr(path, attr, []byte{})
|
| 22 | 22 |
if errno != nil {
|
| ... | ... |
@@ -27,7 +29,7 @@ func Lgetxattr(path string, attr string) ([]byte, error) {
|
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 | 29 |
switch {
|
| 30 |
- case errno == unix.ENODATA: |
|
| 30 |
+ case errors.Is(errno, unix.ENODATA): |
|
| 31 | 31 |
return nil, nil |
| 32 | 32 |
case errno != nil: |
| 33 | 33 |
return sysErr(errno) |
| ... | ... |
@@ -189,7 +189,7 @@ func (s *scanner) Scan(ctx context.Context) bool {
|
| 189 | 189 |
|
| 190 | 190 |
offset := s.pos - int64(readSize) |
| 191 | 191 |
n, err := s.r.ReadAt(s.buf[:readSize], offset) |
| 192 |
- if err != nil && err != io.EOF {
|
|
| 192 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 193 | 193 |
s.err = err |
| 194 | 194 |
return false |
| 195 | 195 |
} |
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"bufio" |
| 5 | 5 |
"bytes" |
| 6 | 6 |
"context" |
| 7 |
+ "errors" |
|
| 7 | 8 |
"fmt" |
| 8 | 9 |
"io" |
| 9 | 10 |
"os" |
| ... | ... |
@@ -130,10 +131,10 @@ truncated line`) |
| 130 | 130 |
if _, err := f.Seek(0, io.SeekStart); err != nil {
|
| 131 | 131 |
t.Fatal(err) |
| 132 | 132 |
} |
| 133 |
- if _, err := TailFile(f, -1); err != ErrNonPositiveLinesNumber {
|
|
| 133 |
+ if _, err := TailFile(f, -1); !errors.Is(err, ErrNonPositiveLinesNumber) {
|
|
| 134 | 134 |
t.Fatalf("Expected ErrNonPositiveLinesNumber, got %v", err)
|
| 135 | 135 |
} |
| 136 |
- if _, err := TailFile(f, 0); err != ErrNonPositiveLinesNumber {
|
|
| 136 |
+ if _, err := TailFile(f, 0); !errors.Is(err, ErrNonPositiveLinesNumber) {
|
|
| 137 | 137 |
t.Fatalf("Expected ErrNonPositiveLinesNumber, got %s", err)
|
| 138 | 138 |
} |
| 139 | 139 |
} |
| ... | ... |
@@ -255,7 +256,7 @@ func TestNewTailReader(t *testing.T) {
|
| 255 | 255 |
return |
| 256 | 256 |
} |
| 257 | 257 |
if len(test.data) == 0 {
|
| 258 |
- assert.Assert(t, err == ErrNonPositiveLinesNumber, err) |
|
| 258 |
+ assert.Assert(t, errors.Is(err, ErrNonPositiveLinesNumber), err) |
|
| 259 | 259 |
return |
| 260 | 260 |
} |
| 261 | 261 |
|
| ... | ... |
@@ -285,7 +286,7 @@ func TestNewTailReader(t *testing.T) {
|
| 285 | 285 |
assert.Check(t, string(data) == "b", string(data)) |
| 286 | 286 |
|
| 287 | 287 |
_, _, err = rdr.ReadLine() |
| 288 |
- assert.Assert(t, err == io.EOF, err) |
|
| 288 |
+ assert.Assert(t, errors.Is(err, io.EOF), err) |
|
| 289 | 289 |
}) |
| 290 | 290 |
}) |
| 291 | 291 |
t.Run("truncated last line", func(t *testing.T) {
|
| ... | ... |
@@ -304,7 +305,7 @@ func TestNewTailReader(t *testing.T) {
|
| 304 | 304 |
assert.Check(t, string(data) == "b", string(data)) |
| 305 | 305 |
|
| 306 | 306 |
_, _, err = rdr.ReadLine() |
| 307 |
- assert.Assert(t, err == io.EOF, err) |
|
| 307 |
+ assert.Assert(t, errors.Is(err, io.EOF), err) |
|
| 308 | 308 |
}) |
| 309 | 309 |
}) |
| 310 | 310 |
|
| ... | ... |
@@ -320,7 +321,7 @@ func TestNewTailReader(t *testing.T) {
|
| 320 | 320 |
assert.Check(t, string(data) == "b", string(data)) |
| 321 | 321 |
|
| 322 | 322 |
_, _, err = rdr.ReadLine() |
| 323 |
- assert.Assert(t, err == io.EOF, err) |
|
| 323 |
+ assert.Assert(t, errors.Is(err, io.EOF), err) |
|
| 324 | 324 |
}) |
| 325 | 325 |
}) |
| 326 | 326 |
} |
| ... | ... |
@@ -10,6 +10,7 @@ import ( |
| 10 | 10 |
"crypto/sha256" |
| 11 | 11 |
"crypto/sha512" |
| 12 | 12 |
"encoding/hex" |
| 13 |
+ "errors" |
|
| 13 | 14 |
"fmt" |
| 14 | 15 |
"io" |
| 15 | 16 |
"os" |
| ... | ... |
@@ -545,7 +546,7 @@ func renderSumForHeader(v Version, h *tar.Header, data []byte) (string, error) {
|
| 545 | 545 |
tr := tar.NewReader(ts) |
| 546 | 546 |
for {
|
| 547 | 547 |
hdr, err := tr.Next() |
| 548 |
- if hdr == nil || err == io.EOF {
|
|
| 548 |
+ if hdr == nil || errors.Is(err, io.EOF) {
|
|
| 549 | 549 |
// Signals the end of the archive. |
| 550 | 550 |
break |
| 551 | 551 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package tarsum |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"archive/tar" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"fmt" |
| 6 | 7 |
"strings" |
| 7 | 8 |
"testing" |
| ... | ... |
@@ -74,7 +75,7 @@ func TestGetVersion(t *testing.T) {
|
| 74 | 74 |
// test one that does not exist, to ensure it errors |
| 75 | 75 |
str := "weak+md5:abcdeabcde" |
| 76 | 76 |
_, err := GetVersionFromTarsum(str) |
| 77 |
- if err != ErrNotVersion {
|
|
| 77 |
+ if !errors.Is(err, ErrNotVersion) {
|
|
| 78 | 78 |
t.Fatalf("%q : %s", err, str)
|
| 79 | 79 |
} |
| 80 | 80 |
} |
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package v2 |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"reflect" |
| 5 | 6 |
"testing" |
| 6 | 7 |
) |
| ... | ... |
@@ -23,7 +24,7 @@ func TestNewSettable(t *testing.T) {
|
| 23 | 23 |
|
| 24 | 24 |
for _, c := range contexts {
|
| 25 | 25 |
s, err := newSettable(c.arg) |
| 26 |
- if err != c.err {
|
|
| 26 |
+ if !errors.Is(err, c.err) {
|
|
| 27 | 27 |
t.Fatalf("expected error to be %v, got %v", c.err, err)
|
| 28 | 28 |
} |
| 29 | 29 |
|
| ... | ... |
@@ -61,7 +62,7 @@ func TestIsSettable(t *testing.T) {
|
| 61 | 61 |
for _, c := range contexts {
|
| 62 | 62 |
if res, err := c.set.isSettable(c.allowedSettableFields, c.settable); res != c.result {
|
| 63 | 63 |
t.Fatalf("expected result to be %t, got %t", c.result, res)
|
| 64 |
- } else if err != c.err {
|
|
| 64 |
+ } else if !errors.Is(err, c.err) {
|
|
| 65 | 65 |
t.Fatalf("expected error to be %v, got %v", c.err, err)
|
| 66 | 66 |
} |
| 67 | 67 |
} |
| ... | ... |
@@ -413,11 +413,11 @@ func makeBackingFsDev(home string) (string, error) {
|
| 413 | 413 |
// Re-create just in case someone copied the home directory over to a new device |
| 414 | 414 |
unix.Unlink(backingFsBlockDev) |
| 415 | 415 |
err := unix.Mknod(backingFsBlockDev, unix.S_IFBLK|0o600, int(stat.Dev)) |
| 416 |
- switch err {
|
|
| 417 |
- case nil: |
|
| 416 |
+ switch {
|
|
| 417 |
+ case err == nil: |
|
| 418 | 418 |
return backingFsBlockDev, nil |
| 419 | 419 |
|
| 420 |
- case unix.ENOSYS, unix.EPERM: |
|
| 420 |
+ case errors.Is(err, unix.ENOSYS), errors.Is(err, unix.EPERM): |
|
| 421 | 421 |
return "", ErrQuotaNotSupported |
| 422 | 422 |
|
| 423 | 423 |
default: |
| ... | ... |
@@ -3,6 +3,7 @@ |
| 3 | 3 |
package quota |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
+ "errors" |
|
| 6 | 7 |
"io" |
| 7 | 8 |
"os" |
| 8 | 9 |
"path/filepath" |
| ... | ... |
@@ -62,7 +63,7 @@ func testBiggerThanQuota(t *testing.T, ctrl *Control, homeDir, testDir, testSubD |
| 62 | 62 |
biggerThanQuotaFile := filepath.Join(testSubDir, "bigger-than-quota") |
| 63 | 63 |
err := os.WriteFile(biggerThanQuotaFile, make([]byte, testQuotaSize+1), 0o644) |
| 64 | 64 |
assert.ErrorContains(t, err, "") |
| 65 |
- if err == io.ErrShortWrite {
|
|
| 65 |
+ if errors.Is(err, io.ErrShortWrite) {
|
|
| 66 | 66 |
assert.NilError(t, os.Remove(biggerThanQuotaFile)) |
| 67 | 67 |
} |
| 68 | 68 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package reference |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"bytes" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"os" |
| 6 | 7 |
"path/filepath" |
| 7 | 8 |
"testing" |
| ... | ... |
@@ -228,7 +229,7 @@ func TestAddDeleteGet(t *testing.T) {
|
| 228 | 228 |
if err != nil {
|
| 229 | 229 |
t.Fatalf("could not parse reference: %v", err)
|
| 230 | 230 |
} |
| 231 |
- if _, err = store.Get(nonExistRepo); err != ErrDoesNotExist {
|
|
| 231 |
+ if _, err = store.Get(nonExistRepo); !errors.Is(err, ErrDoesNotExist) {
|
|
| 232 | 232 |
t.Fatal("Expected ErrDoesNotExist from Get")
|
| 233 | 233 |
} |
| 234 | 234 |
|
| ... | ... |
@@ -237,7 +238,7 @@ func TestAddDeleteGet(t *testing.T) {
|
| 237 | 237 |
if err != nil {
|
| 238 | 238 |
t.Fatalf("could not parse reference: %v", err)
|
| 239 | 239 |
} |
| 240 |
- if _, err = store.Get(nonExistTag); err != ErrDoesNotExist {
|
|
| 240 |
+ if _, err = store.Get(nonExistTag); !errors.Is(err, ErrDoesNotExist) {
|
|
| 241 | 241 |
t.Fatal("Expected ErrDoesNotExist from Get")
|
| 242 | 242 |
} |
| 243 | 243 |
|
| ... | ... |
@@ -289,12 +290,12 @@ func TestAddDeleteGet(t *testing.T) {
|
| 289 | 289 |
} |
| 290 | 290 |
|
| 291 | 291 |
// Delete should return ErrDoesNotExist for a nonexistent repo |
| 292 |
- if _, err = store.Delete(nonExistRepo); err != ErrDoesNotExist {
|
|
| 292 |
+ if _, err = store.Delete(nonExistRepo); !errors.Is(err, ErrDoesNotExist) {
|
|
| 293 | 293 |
t.Fatal("Expected ErrDoesNotExist from Delete")
|
| 294 | 294 |
} |
| 295 | 295 |
|
| 296 | 296 |
// Delete should return ErrDoesNotExist for a nonexistent tag |
| 297 |
- if _, err = store.Delete(nonExistTag); err != ErrDoesNotExist {
|
|
| 297 |
+ if _, err = store.Delete(nonExistTag); !errors.Is(err, ErrDoesNotExist) {
|
|
| 298 | 298 |
t.Fatal("Expected ErrDoesNotExist from Delete")
|
| 299 | 299 |
} |
| 300 | 300 |
|
| ... | ... |
@@ -302,19 +303,19 @@ func TestAddDeleteGet(t *testing.T) {
|
| 302 | 302 |
if deleted, err := store.Delete(ref1); err != nil || !deleted {
|
| 303 | 303 |
t.Fatal("Delete failed")
|
| 304 | 304 |
} |
| 305 |
- if _, err := store.Get(ref1); err != ErrDoesNotExist {
|
|
| 305 |
+ if _, err := store.Get(ref1); !errors.Is(err, ErrDoesNotExist) {
|
|
| 306 | 306 |
t.Fatal("Expected ErrDoesNotExist from Get")
|
| 307 | 307 |
} |
| 308 | 308 |
if deleted, err := store.Delete(ref5); err != nil || !deleted {
|
| 309 | 309 |
t.Fatal("Delete failed")
|
| 310 | 310 |
} |
| 311 |
- if _, err := store.Get(ref5); err != ErrDoesNotExist {
|
|
| 311 |
+ if _, err := store.Get(ref5); !errors.Is(err, ErrDoesNotExist) {
|
|
| 312 | 312 |
t.Fatal("Expected ErrDoesNotExist from Get")
|
| 313 | 313 |
} |
| 314 | 314 |
if deleted, err := store.Delete(nameOnly); err != nil || !deleted {
|
| 315 | 315 |
t.Fatal("Delete failed")
|
| 316 | 316 |
} |
| 317 |
- if _, err := store.Get(nameOnly); err != ErrDoesNotExist {
|
|
| 317 |
+ if _, err := store.Get(nameOnly); !errors.Is(err, ErrDoesNotExist) {
|
|
| 318 | 318 |
t.Fatal("Expected ErrDoesNotExist from Get")
|
| 319 | 319 |
} |
| 320 | 320 |
} |
| ... | ... |
@@ -2,6 +2,7 @@ package resumable |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"fmt" |
| 6 | 7 |
"io" |
| 7 | 8 |
"net/http" |
| ... | ... |
@@ -77,7 +78,7 @@ func (r *requestReader) Read(p []byte) (n int, _ error) {
|
| 77 | 77 |
if err != nil {
|
| 78 | 78 |
r.cleanUpResponse() |
| 79 | 79 |
} |
| 80 |
- if err != nil && err != io.EOF {
|
|
| 80 |
+ if err != nil && !errors.Is(err, io.EOF) {
|
|
| 81 | 81 |
log.G(context.TODO()).Infof("encountered error during pull and clearing it before resume: %s", err)
|
| 82 | 82 |
err = nil |
| 83 | 83 |
} |
| ... | ... |
@@ -693,7 +693,7 @@ func (d *Daemon) Stop(t testing.TB) {
|
| 693 | 693 |
t.Helper() |
| 694 | 694 |
err := d.StopWithError() |
| 695 | 695 |
if err != nil {
|
| 696 |
- if err != errDaemonNotStarted {
|
|
| 696 |
+ if !errors.Is(err, errDaemonNotStarted) {
|
|
| 697 | 697 |
t.Fatalf("[%s] error while stopping the daemon: %v", d.id, err)
|
| 698 | 698 |
} else {
|
| 699 | 699 |
t.Logf("[%s] daemon is not started", d.id)
|
| ... | ... |
@@ -1,6 +1,7 @@ |
| 1 | 1 |
package daemon |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 |
+ "errors" |
|
| 4 | 5 |
"fmt" |
| 5 | 6 |
"os" |
| 6 | 7 |
"path/filepath" |
| ... | ... |
@@ -19,7 +20,7 @@ func cleanupNetworkNamespace(t testing.TB, d *Daemon) {
|
| 19 | 19 |
// cleaned up when a new daemon is instantiated with a |
| 20 | 20 |
// new exec root. |
| 21 | 21 |
filepath.WalkDir(filepath.Join(d.execRoot, "netns"), func(path string, _ os.DirEntry, _ error) error {
|
| 22 |
- if err := unix.Unmount(path, unix.MNT_DETACH); err != nil && err != unix.EINVAL && err != unix.ENOENT {
|
|
| 22 |
+ if err := unix.Unmount(path, unix.MNT_DETACH); err != nil && !errors.Is(err, unix.EINVAL) && !errors.Is(err, unix.ENOENT) {
|
|
| 23 | 23 |
t.Logf("[%s] unmount of %s failed: %v", d.id, path, err)
|
| 24 | 24 |
} |
| 25 | 25 |
os.Remove(path) |
| ... | ... |
@@ -2,6 +2,7 @@ package service |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"context" |
| 5 |
+ "errors" |
|
| 5 | 6 |
"sync" |
| 6 | 7 |
|
| 7 | 8 |
"github.com/containerd/log" |
| ... | ... |
@@ -35,7 +36,7 @@ func (s *VolumeStore) restore() {
|
| 35 | 35 |
var err error |
| 36 | 36 |
if meta.Driver != "" {
|
| 37 | 37 |
v, err = lookupVolume(ctx, s.drivers, meta.Driver, meta.Name) |
| 38 |
- if err != nil && err != errNoSuchVolume {
|
|
| 38 |
+ if err != nil && !errors.Is(err, errNoSuchVolume) {
|
|
| 39 | 39 |
log.G(ctx).WithError(err).WithField("driver", meta.Driver).WithField("volume", meta.Name).Warn("Error restoring volume")
|
| 40 | 40 |
return |
| 41 | 41 |
} |
| ... | ... |
@@ -47,7 +48,7 @@ func (s *VolumeStore) restore() {
|
| 47 | 47 |
} else {
|
| 48 | 48 |
v, err = s.getVolume(ctx, meta.Name, meta.Driver) |
| 49 | 49 |
if err != nil {
|
| 50 |
- if err == errNoSuchVolume {
|
|
| 50 |
+ if errors.Is(err, errNoSuchVolume) {
|
|
| 51 | 51 |
chRemove <- &meta |
| 52 | 52 |
} |
| 53 | 53 |
return |