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:
@@ -37,7 +37,6 @@ import (
|
||||
"github.com/containerd/containerd/sys"
|
||||
"github.com/containerd/containerd/tracing"
|
||||
"github.com/containerd/containerd/version"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"google.golang.org/grpc/grpclog"
|
||||
@@ -155,7 +154,7 @@ can be used and modified as necessary as a custom configuration.`
|
||||
|
||||
// cleanup temp mounts
|
||||
if err := mount.SetTempMountLocation(filepath.Join(config.Root, "tmpmounts")); err != nil {
|
||||
return errors.Wrap(err, "creating temp mount location")
|
||||
return fmt.Errorf("creating temp mount location: %w", err)
|
||||
}
|
||||
// unmount all temp mounts on boot for the server
|
||||
warnings, err := mount.CleanupTempMounts(0)
|
||||
@@ -167,7 +166,7 @@ can be used and modified as necessary as a custom configuration.`
|
||||
}
|
||||
|
||||
if config.GRPC.Address == "" {
|
||||
return errors.Wrap(errdefs.ErrInvalidArgument, "grpc address cannot be empty")
|
||||
return fmt.Errorf("grpc address cannot be empty: %w", errdefs.ErrInvalidArgument)
|
||||
}
|
||||
if config.TTRPC.Address == "" {
|
||||
// If TTRPC was not explicitly configured, use defaults based on GRPC.
|
||||
@@ -235,11 +234,11 @@ can be used and modified as necessary as a custom configuration.`
|
||||
var l net.Listener
|
||||
if isLocalAddress(config.Debug.Address) {
|
||||
if l, err = sys.GetLocalListener(config.Debug.Address, config.Debug.UID, config.Debug.GID); err != nil {
|
||||
return errors.Wrapf(err, "failed to get listener for debug endpoint")
|
||||
return fmt.Errorf("failed to get listener for debug endpoint: %w", err)
|
||||
}
|
||||
} else {
|
||||
if l, err = net.Listen("tcp", config.Debug.Address); err != nil {
|
||||
return errors.Wrapf(err, "failed to get listener for debug endpoint")
|
||||
return fmt.Errorf("failed to get listener for debug endpoint: %w", err)
|
||||
}
|
||||
}
|
||||
serve(ctx, l, server.ServeDebug)
|
||||
@@ -247,28 +246,28 @@ can be used and modified as necessary as a custom configuration.`
|
||||
if config.Metrics.Address != "" {
|
||||
l, err := net.Listen("tcp", config.Metrics.Address)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get listener for metrics endpoint")
|
||||
return fmt.Errorf("failed to get listener for metrics endpoint: %w", err)
|
||||
}
|
||||
serve(ctx, l, server.ServeMetrics)
|
||||
}
|
||||
// setup the ttrpc endpoint
|
||||
tl, err := sys.GetLocalListener(config.TTRPC.Address, config.TTRPC.UID, config.TTRPC.GID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get listener for main ttrpc endpoint")
|
||||
return fmt.Errorf("failed to get listener for main ttrpc endpoint: %w", err)
|
||||
}
|
||||
serve(ctx, tl, server.ServeTTRPC)
|
||||
|
||||
if config.GRPC.TCPAddress != "" {
|
||||
l, err := net.Listen("tcp", config.GRPC.TCPAddress)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get listener for TCP grpc endpoint")
|
||||
return fmt.Errorf("failed to get listener for TCP grpc endpoint: %w", err)
|
||||
}
|
||||
serve(ctx, l, server.ServeTCP)
|
||||
}
|
||||
// setup the main grpc endpoint
|
||||
l, err := sys.GetLocalListener(config.GRPC.Address, config.GRPC.UID, config.GRPC.GID)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed to get listener for main endpoint")
|
||||
return fmt.Errorf("failed to get listener for main endpoint: %w", err)
|
||||
}
|
||||
serve(ctx, l, server.ServeGRPC)
|
||||
|
||||
@@ -364,7 +363,7 @@ func setLogFormat(config *srvconfig.Config) error {
|
||||
TimestampFormat: log.RFC3339NanoFixed,
|
||||
})
|
||||
default:
|
||||
return errors.Errorf("unknown log format: %s", f)
|
||||
return fmt.Errorf("unknown log format: %s", f)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -18,6 +18,7 @@ package command
|
||||
|
||||
import (
|
||||
gocontext "context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"os"
|
||||
@@ -28,7 +29,6 @@ import (
|
||||
"github.com/containerd/containerd/namespaces"
|
||||
"github.com/containerd/containerd/pkg/dialer"
|
||||
"github.com/gogo/protobuf/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/urfave/cli"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/backoff"
|
||||
@@ -52,7 +52,7 @@ var publishCommand = cli.Command{
|
||||
ctx := namespaces.WithNamespace(gocontext.Background(), context.String("namespace"))
|
||||
topic := context.String("topic")
|
||||
if topic == "" {
|
||||
return errors.Wrap(errdefs.ErrInvalidArgument, "topic required to publish event")
|
||||
return fmt.Errorf("topic required to publish event: %w", errdefs.ErrInvalidArgument)
|
||||
}
|
||||
payload, err := getEventPayload(os.Stdin)
|
||||
if err != nil {
|
||||
@@ -87,7 +87,7 @@ func getEventPayload(r io.Reader) (*types.Any, error) {
|
||||
func connectEvents(address string) (eventsapi.EventsClient, error) {
|
||||
conn, err := connect(address, dialer.ContextDialer)
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to dial %q", address)
|
||||
return nil, fmt.Errorf("failed to dial %q: %w", address, err)
|
||||
}
|
||||
return eventsapi.NewEventsClient(conn), nil
|
||||
}
|
||||
@@ -109,7 +109,7 @@ func connect(address string, d func(gocontext.Context, string) (net.Conn, error)
|
||||
defer cancel()
|
||||
conn, err := grpc.DialContext(ctx, 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)
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/errdefs"
|
||||
"github.com/containerd/containerd/services/server"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
exec "golang.org/x/sys/execabs"
|
||||
@@ -218,7 +217,7 @@ func registerUnregisterService(root string) (bool, error) {
|
||||
|
||||
if unregisterServiceFlag {
|
||||
if registerServiceFlag {
|
||||
return true, errors.Wrap(errdefs.ErrInvalidArgument, "--register-service and --unregister-service cannot be used together")
|
||||
return true, fmt.Errorf("--register-service and --unregister-service cannot be used together: %w", errdefs.ErrInvalidArgument)
|
||||
}
|
||||
return true, unregisterService()
|
||||
}
|
||||
@@ -242,7 +241,7 @@ func registerUnregisterService(root string) (bool, error) {
|
||||
// and we want to make sure stderr goes to the panic file.
|
||||
r, _, err := allocConsole.Call()
|
||||
if r == 0 && err != nil {
|
||||
return true, fmt.Errorf("error allocating conhost: %s", err)
|
||||
return true, fmt.Errorf("error allocating conhost: %w", err)
|
||||
}
|
||||
|
||||
if err := initPanicFile(filepath.Join(root, "panic.log")); err != nil {
|
||||
@@ -253,7 +252,7 @@ func registerUnregisterService(root string) (bool, error) {
|
||||
if logFileFlag != "" {
|
||||
f, err := os.OpenFile(logFileFlag, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
|
||||
if err != nil {
|
||||
return true, errors.Wrapf(err, "open log file %q", logFileFlag)
|
||||
return true, fmt.Errorf("open log file %q: %w", logFileFlag, err)
|
||||
}
|
||||
logOutput = f
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user