From 9a57ea886934a79c17663ae22640f2288e3a85a1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 9 May 2020 21:28:48 +0200 Subject: [PATCH] Update some uses of errors.Cause() to errors.Is() Signed-off-by: Sebastiaan van Stijn (cherry picked from commit bb7ef2cb3afba7787388cc9d65017b8135393ec8) Signed-off-by: Sebastiaan van Stijn --- cli-plugins/manager/error.go | 5 +++++ cli-plugins/manager/error_test.go | 2 +- cli/config/config_test.go | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cli-plugins/manager/error.go b/cli-plugins/manager/error.go index 1ad2867869..11822d660c 100644 --- a/cli-plugins/manager/error.go +++ b/cli-plugins/manager/error.go @@ -25,6 +25,11 @@ func (e *pluginError) Cause() error { return e.cause } +// Unwrap provides compatibility for Go 1.13 error chains. +func (e *pluginError) Unwrap() error { + return e.cause +} + // MarshalText marshalls the pluginError into a textual form. func (e *pluginError) MarshalText() (text []byte, err error) { return []byte(e.cause.Error()), nil diff --git a/cli-plugins/manager/error_test.go b/cli-plugins/manager/error_test.go index bc318251ba..fbdb57fd4d 100644 --- a/cli-plugins/manager/error_test.go +++ b/cli-plugins/manager/error_test.go @@ -16,7 +16,7 @@ func TestPluginError(t *testing.T) { inner := fmt.Errorf("testing") err = wrapAsPluginError(inner, "wrapping") assert.Error(t, err, "wrapping: testing") - assert.Equal(t, inner, errors.Cause(err)) + assert.Assert(t, errors.Is(err, inner)) actual, err := yaml.Marshal(err) assert.NilError(t, err) diff --git a/cli/config/config_test.go b/cli/config/config_test.go index bf41d6328f..19d0129519 100644 --- a/cli/config/config_test.go +++ b/cli/config/config_test.go @@ -80,7 +80,7 @@ func TestEmptyFile(t *testing.T) { assert.NilError(t, err) _, err = Load(tmpHome) - assert.Equal(t, errors.Cause(err), io.EOF) + assert.Assert(t, errors.Is(err, io.EOF)) assert.ErrorContains(t, err, ConfigFileName) }