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,12 +18,12 @@ package plugin
import (
"context"
"fmt"
"path/filepath"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/events/exchange"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)
// InitContext is used for plugin initialization
@@ -117,7 +117,7 @@ func (ps *Set) Add(p *Plugin) error {
} else if _, idok := byID[p.Registration.ID]; !idok {
byID[p.Registration.ID] = p
} else {
return errors.Wrapf(errdefs.ErrAlreadyExists, "plugin %v already initialized", p.Registration.URI())
return fmt.Errorf("plugin %v already initialized: %w", p.Registration.URI(), errdefs.ErrAlreadyExists)
}
ps.ordered = append(ps.ordered, p)
@@ -129,7 +129,7 @@ func (ps *Set) Get(t Type) (interface{}, error) {
for _, v := range ps.byTypeAndID[t] {
return v.Instance()
}
return nil, errors.Wrapf(errdefs.ErrNotFound, "no plugins registered for %s", t)
return nil, fmt.Errorf("no plugins registered for %s: %w", t, errdefs.ErrNotFound)
}
// GetAll plugins in the set
@@ -145,7 +145,7 @@ func (i *InitContext) GetByID(t Type, id string) (interface{}, error) {
}
p, ok := ps[id]
if !ok {
return nil, errors.Wrapf(errdefs.ErrNotFound, "no %s plugins with id %s", t, id)
return nil, fmt.Errorf("no %s plugins with id %s: %w", t, id, errdefs.ErrNotFound)
}
return p.Instance()
}
@@ -154,7 +154,7 @@ func (i *InitContext) GetByID(t Type, id string) (interface{}, error) {
func (i *InitContext) GetByType(t Type) (map[string]*Plugin, error) {
p, ok := i.plugins.byTypeAndID[t]
if !ok {
return nil, errors.Wrapf(errdefs.ErrNotFound, "no plugins registered for %s", t)
return nil, fmt.Errorf("no plugins registered for %s: %w", t, errdefs.ErrNotFound)
}
return p, nil

View File

@@ -17,10 +17,9 @@
package plugin
import (
"errors"
"fmt"
"sync"
"github.com/pkg/errors"
)
var (
@@ -172,7 +171,7 @@ func Register(r *Registration) {
func checkUnique(r *Registration) error {
for _, registered := range register.r {
if r.URI() == registered.URI() {
return errors.Wrap(ErrIDRegistered, r.URI())
return fmt.Errorf("%s: %w", r.URI(), ErrIDRegistered)
}
}
return nil