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

@@ -19,6 +19,7 @@ package metadata
import (
"context"
"encoding/binary"
"errors"
"fmt"
"io"
"math/rand"
@@ -43,7 +44,6 @@ import (
"github.com/gogo/protobuf/types"
digest "github.com/opencontainers/go-digest"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
bolt "go.etcd.io/bbolt"
)
@@ -208,7 +208,7 @@ func TestMigrations(t *testing.T) {
check: func(tx *bolt.Tx) error {
bkt := getSnapshotterBucket(tx, "testing", "testing")
if bkt == nil {
return errors.Wrap(errdefs.ErrNotFound, "snapshots bucket not found")
return fmt.Errorf("snapshots bucket not found: %w", errdefs.ErrNotFound)
}
snapshots := []struct {
key string
@@ -235,7 +235,7 @@ func TestMigrations(t *testing.T) {
for _, s := range snapshots {
sbkt := bkt.Bucket([]byte(s.key))
if sbkt == nil {
return errors.Wrap(errdefs.ErrNotFound, "key does not exist")
return fmt.Errorf("key does not exist: %w", errdefs.ErrNotFound)
}
cbkt := sbkt.Bucket(bucketKeyChildren)
@@ -245,12 +245,12 @@ func TestMigrations(t *testing.T) {
}
if cn != len(s.children) {
return errors.Errorf("unexpected number of children %d, expected %d", cn, len(s.children))
return fmt.Errorf("unexpected number of children %d, expected %d", cn, len(s.children))
}
for _, ch := range s.children {
if v := cbkt.Get([]byte(ch)); v == nil {
return errors.Errorf("missing child record for %s", ch)
return fmt.Errorf("missing child record for %s", ch)
}
}
}
@@ -277,18 +277,18 @@ func TestMigrations(t *testing.T) {
check: func(tx *bolt.Tx) error {
bkt := getIngestsBucket(tx, "testing")
if bkt == nil {
return errors.Wrap(errdefs.ErrNotFound, "ingests bucket not found")
return fmt.Errorf("ingests bucket not found: %w", errdefs.ErrNotFound)
}
for _, s := range testRefs {
sbkt := bkt.Bucket([]byte(s.ref))
if sbkt == nil {
return errors.Wrap(errdefs.ErrNotFound, "ref does not exist")
return fmt.Errorf("ref does not exist: %w", errdefs.ErrNotFound)
}
bref := string(sbkt.Get(bucketKeyRef))
if bref != s.bref {
return errors.Errorf("unexpected reference key %q, expected %q", bref, s.bref)
return fmt.Errorf("unexpected reference key %q, expected %q", bref, s.bref)
}
}
@@ -345,11 +345,11 @@ func readDBVersion(db *bolt.DB, schema []byte) (int, error) {
if err := db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(schema)
if bkt == nil {
return errors.Wrap(errdefs.ErrNotFound, "no version bucket")
return fmt.Errorf("no version bucket: %w", errdefs.ErrNotFound)
}
vb := bkt.Get(bucketKeyDBVersion)
if vb == nil {
return errors.Wrap(errdefs.ErrNotFound, "no version value")
return fmt.Errorf("no version value: %w", errdefs.ErrNotFound)
}
v, _ := binary.Varint(vb)
version = int(v)
@@ -588,13 +588,13 @@ func create(obj object, tx *bolt.Tx, db *DB, cs content.Store, sn snapshots.Snap
content.WithRef("test-ref"),
content.WithDescriptor(ocispec.Descriptor{Size: int64(len(v.data)), Digest: expected}))
if err != nil {
return nil, errors.Wrap(err, "failed to create writer")
return nil, fmt.Errorf("failed to create writer: %w", err)
}
if _, err := w.Write(v.data); err != nil {
return nil, errors.Wrap(err, "write blob failed")
return nil, fmt.Errorf("write blob failed: %w", err)
}
if err := w.Commit(ctx, int64(len(v.data)), expected, content.WithLabels(obj.labels)); err != nil {
return nil, errors.Wrap(err, "failed to commit blob")
return nil, fmt.Errorf("failed to commit blob: %w", err)
}
if !obj.removed {
node = &gc.Node{
@@ -635,7 +635,7 @@ func create(obj object, tx *bolt.Tx, db *DB, cs content.Store, sn snapshots.Snap
_, err := NewImageStore(db).Create(ctx, image)
if err != nil {
return nil, errors.Wrap(err, "failed to create image")
return nil, fmt.Errorf("failed to create image: %w", err)
}
case testContainer:
container := containers.Container{