feat: replace github.com/pkg/errors to errors
Signed-off-by: haoyun <yun.hao@daocloud.io> Co-authored-by: zounengren <zouyee1989@gmail.com>
This commit is contained in:
22
unpacker.go
22
unpacker.go
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sync"
|
||||
@@ -36,7 +37,6 @@ import (
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"golang.org/x/sync/semaphore"
|
||||
@@ -92,18 +92,18 @@ func (u *unpacker) unpack(
|
||||
|
||||
var i ocispec.Image
|
||||
if err := json.Unmarshal(p, &i); err != nil {
|
||||
return errors.Wrap(err, "unmarshal image config")
|
||||
return fmt.Errorf("unmarshal image config: %w", err)
|
||||
}
|
||||
diffIDs := i.RootFS.DiffIDs
|
||||
if len(layers) != len(diffIDs) {
|
||||
return errors.Errorf("number of layers and diffIDs don't match: %d != %d", len(layers), len(diffIDs))
|
||||
return fmt.Errorf("number of layers and diffIDs don't match: %d != %d", len(layers), len(diffIDs))
|
||||
}
|
||||
|
||||
if u.config.CheckPlatformSupported {
|
||||
imgPlatform := platforms.Normalize(ocispec.Platform{OS: i.OS, Architecture: i.Architecture})
|
||||
snapshotterPlatformMatcher, err := u.c.GetSnapshotterSupportedPlatforms(ctx, u.snapshotter)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to find supported platforms for snapshotter %s", u.snapshotter)
|
||||
return fmt.Errorf("failed to find supported platforms for snapshotter %s: %w", u.snapshotter, err)
|
||||
}
|
||||
if !snapshotterPlatformMatcher.Match(imgPlatform) {
|
||||
return fmt.Errorf("snapshotter %s does not support platform %s for image %s", u.snapshotter, imgPlatform, config.Digest)
|
||||
@@ -137,7 +137,7 @@ EachLayer:
|
||||
// no need to handle
|
||||
continue
|
||||
} else if !errdefs.IsNotFound(err) {
|
||||
return errors.Wrapf(err, "failed to stat snapshot %s", chainID)
|
||||
return fmt.Errorf("failed to stat snapshot %s: %w", chainID, err)
|
||||
}
|
||||
|
||||
// inherits annotations which are provided as snapshot labels.
|
||||
@@ -161,7 +161,7 @@ EachLayer:
|
||||
if errdefs.IsAlreadyExists(err) {
|
||||
if _, err := sn.Stat(ctx, chainID); err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
return errors.Wrapf(err, "failed to stat snapshot %s", chainID)
|
||||
return fmt.Errorf("failed to stat snapshot %s: %w", chainID, err)
|
||||
}
|
||||
// Try again, this should be rare, log it
|
||||
log.G(ctx).WithField("key", key).WithField("chainid", chainID).Debug("extraction snapshot already exists, chain id not found")
|
||||
@@ -170,14 +170,14 @@ EachLayer:
|
||||
continue EachLayer
|
||||
}
|
||||
} else {
|
||||
return errors.Wrapf(err, "failed to prepare extraction snapshot %q", key)
|
||||
return fmt.Errorf("failed to prepare extraction snapshot %q: %w", key, err)
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to prepare extraction snapshot")
|
||||
return fmt.Errorf("unable to prepare extraction snapshot: %w", err)
|
||||
}
|
||||
|
||||
// Abort the snapshot if commit does not happen
|
||||
@@ -217,11 +217,11 @@ EachLayer:
|
||||
diff, err := a.Apply(ctx, desc, mounts, u.config.ApplyOpts...)
|
||||
if err != nil {
|
||||
abort()
|
||||
return errors.Wrapf(err, "failed to extract layer %s", diffIDs[i])
|
||||
return fmt.Errorf("failed to extract layer %s: %w", diffIDs[i], err)
|
||||
}
|
||||
if diff.Digest != diffIDs[i] {
|
||||
abort()
|
||||
return errors.Errorf("wrong diff id calculated on extraction %q", diffIDs[i])
|
||||
return fmt.Errorf("wrong diff id calculated on extraction %q", diffIDs[i])
|
||||
}
|
||||
|
||||
if err = sn.Commit(ctx, chainID, key, opts...); err != nil {
|
||||
@@ -229,7 +229,7 @@ EachLayer:
|
||||
if errdefs.IsAlreadyExists(err) {
|
||||
continue
|
||||
}
|
||||
return errors.Wrapf(err, "failed to commit snapshot %s", key)
|
||||
return fmt.Errorf("failed to commit snapshot %s: %w", key, err)
|
||||
}
|
||||
|
||||
// Set the uncompressed label after the uncompressed
|
||||
|
Reference in New Issue
Block a user