From f6709e90cd45e20ecd61a3ee2c9445ef6f51d6ea Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Sun, 1 Jan 2023 14:25:00 +0100 Subject: [PATCH] Make golangci-lint happy by using `errors.As` instead of using type assertion on error (which can fail on wrapped errors) --- msg.go | 8 ++++---- senderror.go | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/msg.go b/msg.go index 16b9c9b..320b427 100644 --- a/msg.go +++ b/msg.go @@ -969,11 +969,11 @@ func (m *Msg) HasSendError() bool { // SendErrorIsTemp returns true if the Msg experienced an error during the message delivery and the // corresponding error was of temporary nature and should be retried later func (m *Msg) SendErrorIsTemp() bool { - e, ok := m.sendError.(*SendError) - if !ok { - return false + var e *SendError + if errors.As(m.sendError, &e) { + return e.isTemp } - return e.isTemp + return false } // SendError returns the senderror field of the Msg diff --git a/senderror.go b/senderror.go index b4fb404..264a318 100644 --- a/senderror.go +++ b/senderror.go @@ -5,6 +5,7 @@ package mail import ( + "errors" "fmt" "strconv" "strings" @@ -94,11 +95,11 @@ func (e *SendError) Error() string { // Is implements the errors.Is functionality and compares the SendErrReason func (e *SendError) Is(et error) bool { - t, ok := et.(*SendError) - if !ok { - return false + var t *SendError + if errors.As(et, &t) { + return e.Reason == t.Reason && e.isTemp == t.isTemp } - return e.Reason == t.Reason && e.isTemp == t.isTemp + return false } // String implements the Stringer interface for the SendErrReason