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:
@@ -17,6 +17,7 @@
|
||||
package images
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/containerd/containerd/cmd/ctr/commands"
|
||||
@@ -24,7 +25,6 @@ import (
|
||||
"github.com/containerd/containerd/images/converter/uncompress"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -74,7 +74,7 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
for _, ps := range pss {
|
||||
p, err := platforms.Parse(ps)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "invalid platform %q", ps)
|
||||
return fmt.Errorf("invalid platform %q: %w", ps, err)
|
||||
}
|
||||
all = append(all, p)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package images
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
@@ -24,7 +26,6 @@ import (
|
||||
"github.com/containerd/containerd/images/archive"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -73,7 +74,7 @@ When '--all-platforms' is given all images in a manifest list must be available.
|
||||
for _, ps := range pss {
|
||||
p, err := platforms.Parse(ps)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "invalid platform %q", ps)
|
||||
return fmt.Errorf("invalid platform %q: %w", ps, err)
|
||||
}
|
||||
all = append(all, p)
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package images
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
@@ -29,7 +30,6 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/pkg/progress"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -82,7 +82,7 @@ var listCommand = cli.Command{
|
||||
)
|
||||
imageList, err := imageStore.List(ctx, filters...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to list images")
|
||||
return fmt.Errorf("failed to list images: %w", err)
|
||||
}
|
||||
if quiet {
|
||||
for _, image := range imageList {
|
||||
@@ -224,7 +224,7 @@ var checkCommand = cli.Command{
|
||||
args := []string(context.Args())
|
||||
imageList, err := client.ListImages(ctx, args...)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed listing images")
|
||||
return fmt.Errorf("failed listing images: %w", err)
|
||||
}
|
||||
if len(imageList) == 0 {
|
||||
log.G(ctx).Debugf("no images found")
|
||||
@@ -248,7 +248,7 @@ var checkCommand = cli.Command{
|
||||
available, required, present, missing, err := images.Check(ctx, contentStore, image.Target(), platforms.Default())
|
||||
if err != nil {
|
||||
if exitErr == nil {
|
||||
exitErr = errors.Wrapf(err, "unable to check %v", image.Name())
|
||||
exitErr = fmt.Errorf("unable to check %v: %w", image.Name(), err)
|
||||
}
|
||||
log.G(ctx).WithError(err).Errorf("unable to check %v", image.Name())
|
||||
status = "error"
|
||||
@@ -284,7 +284,7 @@ var checkCommand = cli.Command{
|
||||
unpacked, err := image.IsUnpacked(ctx, context.String("snapshotter"))
|
||||
if err != nil {
|
||||
if exitErr == nil {
|
||||
exitErr = errors.Wrapf(err, "unable to check unpack for %v", image.Name())
|
||||
exitErr = fmt.Errorf("unable to check unpack for %v: %w", image.Name(), err)
|
||||
}
|
||||
log.G(ctx).WithError(err).Errorf("unable to check unpack for %v", image.Name())
|
||||
}
|
||||
@@ -340,7 +340,7 @@ var removeCommand = cli.Command{
|
||||
if err := imageStore.Delete(ctx, target, opts...); err != nil {
|
||||
if !errdefs.IsNotFound(err) {
|
||||
if exitErr == nil {
|
||||
exitErr = errors.Wrapf(err, "unable to delete %v", target)
|
||||
exitErr = fmt.Errorf("unable to delete %v: %w", target, err)
|
||||
}
|
||||
log.G(ctx).WithError(err).Errorf("unable to delete %v", target)
|
||||
continue
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -93,7 +92,7 @@ When you are done, use the unmount command.
|
||||
ps := context.String("platform")
|
||||
p, err := platforms.Parse(ps)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to parse platform %s", ps)
|
||||
return fmt.Errorf("unable to parse platform %s: %w", ps, err)
|
||||
}
|
||||
|
||||
img, err := client.ImageService().Get(ctx, ref)
|
||||
@@ -103,7 +102,7 @@ When you are done, use the unmount command.
|
||||
|
||||
i := containerd.NewImageWithPlatform(client, img, platforms.Only(p))
|
||||
if err := i.Unpack(ctx, snapshotter); err != nil {
|
||||
return errors.Wrap(err, "error unpacking image")
|
||||
return fmt.Errorf("error unpacking image: %w", err)
|
||||
}
|
||||
|
||||
diffIDs, err := i.RootFS(ctx)
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
"github.com/containerd/containerd/platforms"
|
||||
"github.com/opencontainers/image-spec/identity"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -106,13 +105,13 @@ command. As part of this process, we do the following:
|
||||
if context.Bool("all-platforms") {
|
||||
p, err = images.Platforms(ctx, client.ContentStore(), img.Target)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to resolve image platforms")
|
||||
return fmt.Errorf("unable to resolve image platforms: %w", err)
|
||||
}
|
||||
} else {
|
||||
for _, s := range context.StringSlice("platform") {
|
||||
ps, err := platforms.Parse(s)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "unable to parse platform %s", s)
|
||||
return fmt.Errorf("unable to parse platform %s: %w", s, err)
|
||||
}
|
||||
p = append(p, ps)
|
||||
}
|
||||
|
||||
@@ -18,6 +18,8 @@ package images
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http/httptrace"
|
||||
"os"
|
||||
"sync"
|
||||
@@ -35,7 +37,6 @@ import (
|
||||
"github.com/containerd/containerd/remotes/docker"
|
||||
digest "github.com/opencontainers/go-digest"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
"golang.org/x/sync/errgroup"
|
||||
)
|
||||
@@ -88,7 +89,7 @@ var pushCommand = cli.Command{
|
||||
if manifest := context.String("manifest"); manifest != "" {
|
||||
desc.Digest, err = digest.Parse(manifest)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "invalid manifest digest")
|
||||
return fmt.Errorf("invalid manifest digest: %w", err)
|
||||
}
|
||||
desc.MediaType = context.String("manifest-type")
|
||||
} else {
|
||||
@@ -97,14 +98,14 @@ var pushCommand = cli.Command{
|
||||
}
|
||||
img, err := client.ImageService().Get(ctx, local)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "unable to resolve image to manifest")
|
||||
return fmt.Errorf("unable to resolve image to manifest: %w", err)
|
||||
}
|
||||
desc = img.Target
|
||||
|
||||
if pss := context.StringSlice("platform"); len(pss) == 1 {
|
||||
p, err := platforms.Parse(pss[0])
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "invalid platform %q", pss[0])
|
||||
return fmt.Errorf("invalid platform %q: %w", pss[0], err)
|
||||
}
|
||||
|
||||
cs := client.ContentStore()
|
||||
@@ -113,7 +114,7 @@ var pushCommand = cli.Command{
|
||||
for _, manifest := range manifests {
|
||||
if manifest.Platform != nil && matcher.Match(*manifest.Platform) {
|
||||
if _, err := images.Children(ctx, cs, manifest); err != nil {
|
||||
return errors.Wrap(err, "no matching manifest")
|
||||
return fmt.Errorf("no matching manifest: %w", err)
|
||||
}
|
||||
desc = manifest
|
||||
break
|
||||
|
||||
@@ -23,7 +23,6 @@ import (
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/leases"
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@@ -60,10 +59,10 @@ var unmountCommand = cli.Command{
|
||||
snapshotter := context.String("snapshotter")
|
||||
s := client.SnapshotService(snapshotter)
|
||||
if err := client.LeasesService().Delete(ctx, leases.Lease{ID: target}); err != nil && !errdefs.IsNotFound(err) {
|
||||
return errors.Wrap(err, "error deleting lease")
|
||||
return fmt.Errorf("error deleting lease: %w", err)
|
||||
}
|
||||
if err := s.Remove(ctx, target); err != nil && !errdefs.IsNotFound(err) {
|
||||
return errors.Wrap(err, "error removing snapshot")
|
||||
return fmt.Errorf("error removing snapshot: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user