mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
use errors.Is() to handle image store errors
The image store's used are an interface, so there's no guarantee that implementations don't wrap the errors. Make sure to catch such cases by using errors.Is. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -2,6 +2,7 @@ package images // import "github.com/docker/docker/daemon/images"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sort"
|
||||
"time"
|
||||
@@ -132,7 +133,7 @@ func (i *ImageService) Images(ctx context.Context, opts types.ImageListOptions)
|
||||
if err != nil {
|
||||
// The layer may have been deleted between the call to `Map()` or
|
||||
// `Heads()` and the call to `Get()`, so we just ignore this error
|
||||
if err == layer.ErrLayerDoesNotExist {
|
||||
if errors.Is(err, layer.ErrLayerDoesNotExist) {
|
||||
continue
|
||||
}
|
||||
return nil, err
|
||||
|
||||
@@ -88,7 +88,7 @@ func (is *store) restore() error {
|
||||
}
|
||||
l, err = is.lss.Get(chainID)
|
||||
if err != nil {
|
||||
if err == layer.ErrLayerDoesNotExist {
|
||||
if errors.Is(err, layer.ErrLayerDoesNotExist) {
|
||||
logrus.WithFields(f{"chainID": chainID, "os": img.OperatingSystem(), "err": err}).Error("not restoring image")
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package layer // import "github.com/docker/docker/layer"
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -397,7 +398,7 @@ func TestStoreRestore(t *testing.T) {
|
||||
// Create again with same name, should return error
|
||||
if _, err := ls2.CreateRWLayer("some-mount_name", layer3b.ChainID(), nil); err == nil {
|
||||
t.Fatal("Expected error creating mount with same name")
|
||||
} else if err != ErrMountNameConflict {
|
||||
} else if !errors.Is(err, ErrMountNameConflict) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user