From e863120b51fde0ecab43f4053b73e862a5299246 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Mon, 4 Sep 2023 14:31:59 +0300 Subject: [PATCH] Fix RequestError.Is --- libgm/events/ready.go | 6 +++--- libgm/events/ready_test.go | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/libgm/events/ready.go b/libgm/events/ready.go index 787721a..e9122af 100644 --- a/libgm/events/ready.go +++ b/libgm/events/ready.go @@ -45,9 +45,9 @@ func (re RequestError) Error() string { } func (re RequestError) Is(other error) bool { - otherRe, ok := other.(RequestError) - if !ok { - return errors.Is(*re.HTTP, other) + var otherRe RequestError + if !errors.As(other, &otherRe) { + return re.HTTP != nil && errors.Is(*re.HTTP, other) } return otherRe.Data.GetType() == re.Data.GetType() && otherRe.Data.GetMessage() == re.Data.GetMessage() diff --git a/libgm/events/ready_test.go b/libgm/events/ready_test.go index 24e6b2c..6b14957 100644 --- a/libgm/events/ready_test.go +++ b/libgm/events/ready_test.go @@ -2,6 +2,7 @@ package events_test import ( "encoding/base64" + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -18,6 +19,7 @@ func TestRequestError_Is(t *testing.T) { err := pblite.Unmarshal(dat, &errResp) require.NoError(t, err) assert.ErrorIs(t, events.RequestError{Data: &errResp}, events.ErrRequestedEntityNotFound) + assert.ErrorIs(t, events.RequestError{Data: &errResp}, fmt.Errorf("meow: %w", events.ErrRequestedEntityNotFound)) assert.NotErrorIs(t, events.RequestError{Data: &errResp}, events.RequestError{ Data: &gmproto.ErrorResponse{ Type: 5,