Update some uses of errors.Cause() to errors.Is()

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit bb7ef2cb3a)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-05-09 21:28:48 +02:00
parent 345b0e79e5
commit 9a57ea8869
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
3 changed files with 7 additions and 2 deletions

View File

@ -25,6 +25,11 @@ func (e *pluginError) Cause() error {
return e.cause 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. // MarshalText marshalls the pluginError into a textual form.
func (e *pluginError) MarshalText() (text []byte, err error) { func (e *pluginError) MarshalText() (text []byte, err error) {
return []byte(e.cause.Error()), nil return []byte(e.cause.Error()), nil

View File

@ -16,7 +16,7 @@ func TestPluginError(t *testing.T) {
inner := fmt.Errorf("testing") inner := fmt.Errorf("testing")
err = wrapAsPluginError(inner, "wrapping") err = wrapAsPluginError(inner, "wrapping")
assert.Error(t, err, "wrapping: testing") 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) actual, err := yaml.Marshal(err)
assert.NilError(t, err) assert.NilError(t, err)

View File

@ -80,7 +80,7 @@ func TestEmptyFile(t *testing.T) {
assert.NilError(t, err) assert.NilError(t, err)
_, err = Load(tmpHome) _, err = Load(tmpHome)
assert.Equal(t, errors.Cause(err), io.EOF) assert.Assert(t, errors.Is(err, io.EOF))
assert.ErrorContains(t, err, ConfigFileName) assert.ErrorContains(t, err, ConfigFileName)
} }