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

@@ -17,12 +17,12 @@
package config
import (
"fmt"
"path/filepath"
"strings"
"github.com/imdario/mergo"
"github.com/pelletier/go-toml"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/containerd/containerd/errdefs"
@@ -104,17 +104,17 @@ func (c *Config) ValidateV2() error {
}
for _, p := range c.DisabledPlugins {
if len(strings.Split(p, ".")) < 4 {
return errors.Errorf("invalid disabled plugin URI %q expect io.containerd.x.vx", p)
return fmt.Errorf("invalid disabled plugin URI %q expect io.containerd.x.vx", p)
}
}
for _, p := range c.RequiredPlugins {
if len(strings.Split(p, ".")) < 4 {
return errors.Errorf("invalid required plugin URI %q expect io.containerd.x.vx", p)
return fmt.Errorf("invalid required plugin URI %q expect io.containerd.x.vx", p)
}
}
for p := range c.Plugins {
if len(strings.Split(p, ".")) < 4 {
return errors.Errorf("invalid plugin key URI %q expect io.containerd.x.vx", p)
return fmt.Errorf("invalid plugin key URI %q expect io.containerd.x.vx", p)
}
}
return nil
@@ -201,7 +201,7 @@ func (bc *BoltConfig) Validate() error {
case SharingPolicyShared, SharingPolicyIsolated:
return nil
default:
return errors.Wrapf(errdefs.ErrInvalidArgument, "unknown policy: %s", bc.ContentSharingPolicy)
return fmt.Errorf("unknown policy: %s: %w", bc.ContentSharingPolicy, errdefs.ErrInvalidArgument)
}
}
@@ -224,7 +224,7 @@ func (c *Config) Decode(p *plugin.Registration) (interface{}, error) {
// LoadConfig loads the containerd server config from the provided path
func LoadConfig(path string, out *Config) error {
if out == nil {
return errors.Wrapf(errdefs.ErrInvalidArgument, "argument out must not be nil")
return fmt.Errorf("argument out must not be nil: %w", errdefs.ErrInvalidArgument)
}
var (
@@ -266,7 +266,7 @@ func LoadConfig(path string, out *Config) error {
err := out.ValidateV2()
if err != nil {
return errors.Wrapf(err, "failed to load TOML from %s", path)
return fmt.Errorf("failed to load TOML from %s: %w", path, err)
}
return nil
}
@@ -277,11 +277,11 @@ func loadConfigFile(path string) (*Config, error) {
file, err := toml.LoadFile(path)
if err != nil {
return nil, errors.Wrapf(err, "failed to load TOML: %s", path)
return nil, fmt.Errorf("failed to load TOML: %s: %w", path, err)
}
if err := file.Unmarshal(config); err != nil {
return nil, errors.Wrap(err, "failed to unmarshal TOML")
return nil, fmt.Errorf("failed to unmarshal TOML: %w", err)
}
return config, nil

View File

@@ -20,7 +20,9 @@ import (
"context"
"crypto/tls"
"crypto/x509"
"errors"
"expvar"
"fmt"
"io"
"net"
"net/http"
@@ -53,7 +55,6 @@ import (
metrics "github.com/docker/go-metrics"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/pkg/errors"
bolt "go.etcd.io/bbolt"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc"
@@ -117,7 +118,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
for key, sec := range config.Timeouts {
d, err := time.ParseDuration(sec)
if err != nil {
return nil, errors.Errorf("unable to parse %s into a time duration", sec)
return nil, fmt.Errorf("unable to parse %s into a time duration", sec)
}
timeout.Set(key, d)
}
@@ -165,7 +166,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
caCertPool := x509.NewCertPool()
caCert, err := os.ReadFile(config.GRPC.TCPTLSCA)
if err != nil {
return nil, errors.Wrap(err, "failed to load CA file")
return nil, fmt.Errorf("failed to load CA file: %w", err)
}
caCertPool.AppendCertsFromPEM(caCert)
tlsConfig.ClientCAs = caCertPool
@@ -241,7 +242,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
}
result := p.Init(initContext)
if err := initialized.Add(result); err != nil {
return nil, errors.Wrapf(err, "could not add plugin result to plugin set")
return nil, fmt.Errorf("could not add plugin result to plugin set: %w", err)
}
instance, err := result.Instance()
@@ -252,7 +253,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
log.G(ctx).WithError(err).Warnf("failed to load plugin %s", id)
}
if _, ok := required[reqID]; ok {
return nil, errors.Wrapf(err, "load required plugin %s", id)
return nil, fmt.Errorf("load required plugin %s: %w", id, err)
}
continue
}
@@ -276,7 +277,7 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
for id := range required {
missing = append(missing, id)
}
return nil, errors.Errorf("required plugin %s not included", missing)
return nil, fmt.Errorf("required plugin %s not included", missing)
}
// register services after all plugins have been initialized
@@ -560,7 +561,7 @@ func (pc *proxyClients) getClient(address string) (*grpc.ClientConn, error) {
conn, err := grpc.Dial(dialer.DialAddress(address), gopts...)
if err != nil {
return nil, errors.Wrapf(err, "failed to dial %q", address)
return nil, fmt.Errorf("failed to dial %q: %w", address, err)
}
pc.clients[address] = conn