Replace errors.Cause() with errors.Is()

Dependencies may be switching to use the new `%w` formatting
option to wrap errors; switching to use `errors.Is()` makes
sure that we are still able to unwrap the error and detect the
underlying cause.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2020-05-08 01:03:26 +02:00
parent 834f58bd0c
commit dc92ad6520
25 changed files with 51 additions and 50 deletions

View File

@@ -62,7 +62,7 @@ func (p *Process) State(ctx context.Context) (runtime.State, error) {
ID: p.id,
})
if err != nil {
if errors.Cause(err) != ttrpc.ErrClosed {
if !errors.Is(err, ttrpc.ErrClosed) {
return runtime.State{}, errdefs.FromGRPC(err)
}

View File

@@ -159,7 +159,7 @@ func (t *Task) State(ctx context.Context) (runtime.State, error) {
ID: t.id,
})
if err != nil {
if errors.Cause(err) != ttrpc.ErrClosed {
if !errors.Is(err, ttrpc.ErrClosed) {
return runtime.State{}, errdefs.FromGRPC(err)
}
return runtime.State{}, errdefs.ErrNotFound

View File

@@ -54,7 +54,7 @@ func (p *process) State(ctx context.Context) (runtime.State, error) {
ExecID: p.id,
})
if err != nil {
if errors.Cause(err) != ttrpc.ErrClosed {
if !errors.Is(err, ttrpc.ErrClosed) {
return runtime.State{}, errdefs.FromGRPC(err)
}
return runtime.State{}, errdefs.ErrNotFound

View File

@@ -94,7 +94,7 @@ func loadShim(ctx context.Context, bundle *Bundle, events *exchange.Exchange, rt
// When using a multi-container shim the 2nd to Nth container in the
// shim will not have a separate log pipe. Ignore the failure log
// message here when the shim connect times out.
if !os.IsNotExist(errors.Cause(err)) {
if !errors.Is(err, os.ErrNotExist) {
log.G(ctx).WithError(err).Error("copy shim log")
}
}
@@ -191,7 +191,7 @@ func (s *shim) Shutdown(ctx context.Context) error {
_, err := s.task.Shutdown(ctx, &task.ShutdownRequest{
ID: s.ID(),
})
if err != nil && errors.Cause(err) != ttrpc.ErrClosed {
if err != nil && !errors.Is(err, ttrpc.ErrClosed) {
return errdefs.FromGRPC(err)
}
return nil
@@ -227,7 +227,7 @@ func (s *shim) Delete(ctx context.Context) (*runtime.Exit, error) {
})
if shimErr != nil {
log.G(ctx).WithField("id", s.ID()).WithError(shimErr).Debug("failed to delete task")
if errors.Cause(shimErr) != ttrpc.ErrClosed {
if !errors.Is(shimErr, ttrpc.ErrClosed) {
shimErr = errdefs.FromGRPC(shimErr)
if !errdefs.IsNotFound(shimErr) {
return nil, shimErr
@@ -444,7 +444,7 @@ func (s *shim) State(ctx context.Context) (runtime.State, error) {
ID: s.ID(),
})
if err != nil {
if errors.Cause(err) != ttrpc.ErrClosed {
if !errors.Is(err, ttrpc.ErrClosed) {
return runtime.State{}, errdefs.FromGRPC(err)
}
return runtime.State{}, errdefs.ErrNotFound

View File

@@ -90,7 +90,7 @@ func checkCopyShimLogError(ctx context.Context, err error) error {
// When using a multi-container shim the 2nd to Nth container in the
// shim will not have a separate log pipe. Ignore the failure log
// message here when the shim connect times out.
if os.IsNotExist(errors.Cause(err)) {
if errors.Is(err, os.ErrNotExist) {
return nil
}
return err