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,6 +18,7 @@ package shim
import (
"context"
"errors"
"flag"
"fmt"
"io"
@@ -36,7 +37,6 @@ import (
"github.com/containerd/containerd/version"
"github.com/containerd/ttrpc"
"github.com/gogo/protobuf/proto"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@@ -398,7 +398,7 @@ func run(ctx context.Context, manager Manager, initFunc Init, name string, confi
result := p.Init(initContext)
if err := initialized.Add(result); err != nil {
return errors.Wrapf(err, "could not add plugin result to plugin set")
return fmt.Errorf("could not add plugin result to plugin set: %w", err)
}
instance, err := result.Instance()
@@ -419,12 +419,12 @@ func run(ctx context.Context, manager Manager, initFunc Init, name string, confi
server, err := newServer()
if err != nil {
return errors.Wrap(err, "failed creating server")
return fmt.Errorf("failed creating server: %w", err)
}
for _, srv := range ttrpcServices {
if err := srv.RegisterTTRPC(server); err != nil {
return errors.Wrap(err, "failed to register service")
return fmt.Errorf("failed to register service: %w", err)
}
}

View File

@@ -21,6 +21,7 @@ package shim
import (
"context"
"fmt"
"io"
"net"
"os"
@@ -29,7 +30,6 @@ import (
"github.com/containerd/containerd/sys/reaper"
"github.com/containerd/fifo"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
)
@@ -60,7 +60,7 @@ func serveListener(path string) (net.Listener, error) {
path = "[inherited from parent]"
} else {
if len(path) > socketPathLimit {
return nil, errors.Errorf("%q: unix socket path too long (> %d)", path, socketPathLimit)
return nil, fmt.Errorf("%q: unix socket path too long (> %d)", path, socketPathLimit)
}
l, err = net.Listen("unix", path)
}

View File

@@ -18,12 +18,12 @@ package shim
import (
"context"
"errors"
"io"
"net"
"os"
"github.com/containerd/ttrpc"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)

View File

@@ -19,6 +19,7 @@ package shim
import (
"bytes"
"context"
"errors"
"fmt"
"net"
"os"
@@ -29,7 +30,6 @@ import (
"github.com/containerd/containerd/namespaces"
"github.com/gogo/protobuf/proto"
"github.com/gogo/protobuf/types"
"github.com/pkg/errors"
exec "golang.org/x/sys/execabs"
)

View File

@@ -33,7 +33,6 @@ import (
"github.com/containerd/containerd/defaults"
"github.com/containerd/containerd/namespaces"
"github.com/containerd/containerd/sys"
"github.com/pkg/errors"
)
const (
@@ -54,11 +53,11 @@ func AdjustOOMScore(pid int) error {
parent := os.Getppid()
score, err := sys.GetOOMScoreAdj(parent)
if err != nil {
return errors.Wrap(err, "get parent OOM score")
return fmt.Errorf("get parent OOM score: %w", err)
}
shimScore := score + 1
if err := sys.AdjustOOMScore(pid, shimScore); err != nil {
return errors.Wrap(err, "set shim OOM score")
return fmt.Errorf("set shim OOM score: %w", err)
}
return nil
}
@@ -96,7 +95,7 @@ func NewSocket(address string) (*net.UnixListener, error) {
if !isAbstract {
if err := os.MkdirAll(filepath.Dir(path), 0600); err != nil {
return nil, errors.Wrapf(err, "%s", path)
return nil, fmt.Errorf("%s: %w", path, err)
}
}
l, err := net.Listen("unix", path)

View File

@@ -18,13 +18,13 @@ package shim
import (
"context"
"fmt"
"net"
"os"
"syscall"
"time"
winio "github.com/Microsoft/go-winio"
"github.com/pkg/errors"
)
const shimBinaryFormat = "containerd-shim-%s-%s.exe"
@@ -40,9 +40,9 @@ func AnonReconnectDialer(address string, timeout time.Duration) (net.Conn, error
c, err := winio.DialPipeContext(ctx, address)
if os.IsNotExist(err) {
return nil, errors.Wrap(os.ErrNotExist, "npipe not found on reconnect")
return nil, fmt.Errorf("npipe not found on reconnect: %w", os.ErrNotExist)
} else if err == context.DeadlineExceeded {
return nil, errors.Wrapf(err, "timed out waiting for npipe %s", address)
return nil, fmt.Errorf("timed out waiting for npipe %s: %w", address, err)
} else if err != nil {
return nil, err
}
@@ -65,14 +65,14 @@ func AnonDialer(address string, timeout time.Duration) (net.Conn, error) {
if os.IsNotExist(err) {
select {
case <-serveTimer.C:
return nil, errors.Wrap(os.ErrNotExist, "pipe not found before timeout")
return nil, fmt.Errorf("pipe not found before timeout: %w", os.ErrNotExist)
default:
// Wait 10ms for the shim to serve and try again.
time.Sleep(10 * time.Millisecond)
continue
}
} else if err == context.DeadlineExceeded {
return nil, errors.Wrapf(err, "timed out waiting for npipe %s", address)
return nil, fmt.Errorf("timed out waiting for npipe %s: %w", address, err)
}
return nil, err
}