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:
haoyun
2022-01-07 10:19:31 +08:00
parent 3ccd43c8f6
commit bbe46b8c43
299 changed files with 1896 additions and 1874 deletions

View File

@@ -35,7 +35,6 @@ import (
"github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/storage"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -69,7 +68,7 @@ func NewSnapshotter(root string) (snapshots.Snapshotter, error) {
return nil, err
}
if mnt.FSType != "btrfs" {
return nil, errors.Wrapf(plugin.ErrSkipPlugin, "path %s (%s) must be a btrfs filesystem to be used with the btrfs snapshotter", root, mnt.FSType)
return nil, fmt.Errorf("path %s (%s) must be a btrfs filesystem to be used with the btrfs snapshotter: %w", root, mnt.FSType, plugin.ErrSkipPlugin)
}
var (
active = filepath.Join(root, "active")
@@ -275,7 +274,7 @@ func (b *snapshotter) mounts(dir string, s storage.Snapshot) ([]mount.Mount, err
func (b *snapshotter) Commit(ctx context.Context, name, key string, opts ...snapshots.Opt) (err error) {
usage, err := b.usage(ctx, key)
if err != nil {
return errors.Wrap(err, "failed to compute usage")
return fmt.Errorf("failed to compute usage: %w", err)
}
ctx, t, err := b.ms.TransactionContext(ctx, true)
@@ -292,7 +291,7 @@ func (b *snapshotter) Commit(ctx context.Context, name, key string, opts ...snap
id, err := storage.CommitActive(ctx, key, name, usage, opts...) // TODO(stevvooe): Resolve a usage value for btrfs
if err != nil {
return errors.Wrap(err, "failed to commit")
return fmt.Errorf("failed to commit: %w", err)
}
source := filepath.Join(b.root, "active", id)
@@ -331,7 +330,7 @@ func (b *snapshotter) Mounts(ctx context.Context, key string) ([]mount.Mount, er
s, err := storage.GetSnapshot(ctx, key)
t.Rollback()
if err != nil {
return nil, errors.Wrap(err, "failed to get active snapshot")
return nil, fmt.Errorf("failed to get active snapshot: %w", err)
}
dir := filepath.Join(b.root, strings.ToLower(s.Kind.String()), s.ID)
@@ -366,7 +365,7 @@ func (b *snapshotter) Remove(ctx context.Context, key string) (err error) {
id, k, err := storage.Remove(ctx, key)
if err != nil {
return errors.Wrap(err, "failed to remove snapshot")
return fmt.Errorf("failed to remove snapshot: %w", err)
}
switch k {
@@ -389,7 +388,7 @@ func (b *snapshotter) Remove(ctx context.Context, key string) (err error) {
}
if err := btrfs.SubvolDelete(source); err != nil {
return errors.Wrapf(err, "failed to remove snapshot %v", source)
return fmt.Errorf("failed to remove snapshot %v: %w", source, err)
}
err = t.Commit()

View File

@@ -22,6 +22,8 @@ package btrfs
import (
"bytes"
"context"
"errors"
"fmt"
"os"
"path/filepath"
"strings"
@@ -34,7 +36,6 @@ import (
"github.com/containerd/containerd/snapshots"
"github.com/containerd/containerd/snapshots/testsuite"
"github.com/containerd/continuity/testutil/loopback"
"github.com/pkg/errors"
exec "golang.org/x/sys/execabs"
"golang.org/x/sys/unix"
)
@@ -66,7 +67,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
if out, err := exec.Command(mkbtrfs, loop.Device).CombinedOutput(); err != nil {
loop.Close()
return nil, nil, errors.Wrapf(err, "failed to make btrfs filesystem (out: %q)", out)
return nil, nil, fmt.Errorf("failed to make btrfs filesystem (out: %q): %w", out, err)
}
// sync after a mkfs on the loopback before trying to mount the device
unix.Sync()
@@ -75,7 +76,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
for i := 0; i < 5; i++ {
if out, err := exec.Command("mount", loop.Device, root).CombinedOutput(); err != nil {
loop.Close()
return nil, nil, errors.Wrapf(err, "failed to mount device %s (out: %q)", loop.Device, out)
return nil, nil, fmt.Errorf("failed to mount device %s (out: %q): %w", loop.Device, out, err)
}
if i > 0 {
@@ -95,7 +96,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
unix.Unmount(root, 0)
}
if snapshotter == nil {
return nil, nil, errors.Wrap(err, "failed to successfully create snapshotter after 5 attempts")
return nil, nil, fmt.Errorf("failed to successfully create snapshotter after 5 attempts: %w", err)
}
return snapshotter, func() error {
@@ -104,7 +105,7 @@ func boltSnapshotter(t *testing.T) func(context.Context, string) (snapshots.Snap
}
err := mount.UnmountAll(root, unix.MNT_DETACH)
if cerr := loop.Close(); cerr != nil {
err = errors.Wrap(cerr, "device cleanup failed")
err = fmt.Errorf("device cleanup failed: %w", cerr)
}
return err
}, nil