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

@@ -18,8 +18,8 @@ package container
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)
@@ -85,5 +85,5 @@ func (c *Metadata) UnmarshalJSON(data []byte) error {
*c = Metadata(versioned.Metadata)
return nil
}
return errors.Errorf("unsupported version: %q", versioned.Version)
return fmt.Errorf("unsupported version: %q", versioned.Version)
}

View File

@@ -18,12 +18,13 @@ package container
import (
"encoding/json"
"errors"
"fmt"
"os"
"path/filepath"
"sync"
"github.com/containerd/continuity"
"github.com/pkg/errors"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)
@@ -165,11 +166,11 @@ type StatusStorage interface {
func StoreStatus(root, id string, status Status) (StatusStorage, error) {
data, err := status.encode()
if err != nil {
return nil, errors.Wrap(err, "failed to encode status")
return nil, fmt.Errorf("failed to encode status: %w", err)
}
path := filepath.Join(root, "status")
if err := continuity.AtomicWriteFile(path, data, 0600); err != nil {
return nil, errors.Wrapf(err, "failed to checkpoint status to %q", path)
return nil, fmt.Errorf("failed to checkpoint status to %q: %w", path, err)
}
return &statusStorage{
path: path,
@@ -183,11 +184,11 @@ func LoadStatus(root, id string) (Status, error) {
path := filepath.Join(root, "status")
data, err := os.ReadFile(path)
if err != nil {
return Status{}, errors.Wrapf(err, "failed to read status from %q", path)
return Status{}, fmt.Errorf("failed to read status from %q: %w", path, err)
}
var status Status
if err := status.decode(data); err != nil {
return Status{}, errors.Wrapf(err, "failed to decode status %q", data)
return Status{}, fmt.Errorf("failed to decode status %q: %w", data, err)
}
return status, nil
}
@@ -215,10 +216,10 @@ func (s *statusStorage) UpdateSync(u UpdateFunc) error {
}
data, err := newStatus.encode()
if err != nil {
return errors.Wrap(err, "failed to encode status")
return fmt.Errorf("failed to encode status: %w", err)
}
if err := continuity.AtomicWriteFile(s.path, data, 0600); err != nil {
return errors.Wrapf(err, "failed to checkpoint status to %q", s.path)
return fmt.Errorf("failed to checkpoint status to %q: %w", s.path, err)
}
s.status = newStatus
return nil

View File

@@ -16,7 +16,7 @@
package image
import "github.com/pkg/errors"
import "fmt"
// NewFakeStore returns an image store with predefined images.
// Update is not allowed for this fake store.
@@ -27,7 +27,7 @@ func NewFakeStore(images []Image) (*Store, error) {
s.refCache[ref] = i.ID
}
if err := s.store.add(i); err != nil {
return nil, errors.Wrapf(err, "add image %+v", i)
return nil, fmt.Errorf("add image %+v: %w", i, err)
}
}
return s, nil

View File

@@ -19,6 +19,7 @@ package image
import (
"context"
"encoding/json"
"fmt"
"sync"
"github.com/containerd/containerd"
@@ -30,7 +31,6 @@ import (
"github.com/opencontainers/go-digest/digestset"
imageidentity "github.com/opencontainers/image-spec/identity"
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
// Image contains all resources associated with the image. All fields
@@ -77,13 +77,13 @@ func (s *Store) Update(ctx context.Context, ref string) error {
defer s.lock.Unlock()
i, err := s.client.GetImage(ctx, ref)
if err != nil && !errdefs.IsNotFound(err) {
return errors.Wrap(err, "get image from containerd")
return fmt.Errorf("get image from containerd: %w", err)
}
var img *Image
if err == nil {
img, err = getImage(ctx, i)
if err != nil {
return errors.Wrap(err, "get image info from containerd")
return fmt.Errorf("get image info from containerd: %w", err)
}
}
return s.update(ref, img)
@@ -119,28 +119,28 @@ func getImage(ctx context.Context, i containerd.Image) (*Image, error) {
// Get image information.
diffIDs, err := i.RootFS(ctx)
if err != nil {
return nil, errors.Wrap(err, "get image diffIDs")
return nil, fmt.Errorf("get image diffIDs: %w", err)
}
chainID := imageidentity.ChainID(diffIDs)
size, err := i.Size(ctx)
if err != nil {
return nil, errors.Wrap(err, "get image compressed resource size")
return nil, fmt.Errorf("get image compressed resource size: %w", err)
}
desc, err := i.Config(ctx)
if err != nil {
return nil, errors.Wrap(err, "get image config descriptor")
return nil, fmt.Errorf("get image config descriptor: %w", err)
}
id := desc.Digest.String()
rb, err := content.ReadBlob(ctx, i.ContentStore(), desc)
if err != nil {
return nil, errors.Wrap(err, "read image config from content store")
return nil, fmt.Errorf("read image config from content store: %w", err)
}
var ociimage imagespec.Image
if err := json.Unmarshal(rb, &ociimage); err != nil {
return nil, errors.Wrapf(err, "unmarshal image config %s", rb)
return nil, fmt.Errorf("unmarshal image config %s: %w", rb, err)
}
return &Image{

View File

@@ -18,9 +18,9 @@ package sandbox
import (
"encoding/json"
"fmt"
cni "github.com/containerd/go-cni"
"github.com/pkg/errors"
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
)
@@ -85,5 +85,5 @@ func (c *Metadata) UnmarshalJSON(data []byte) error {
*c = Metadata(versioned.Metadata)
return nil
}
return errors.Errorf("unsupported version: %q", versioned.Version)
return fmt.Errorf("unsupported version: %q", versioned.Version)
}