Make golangci-lint happy by using errors.As instead of using type assertion on error (which can fail on wrapped errors)

This commit is contained in:
Winni Neessen 2023-01-01 14:25:00 +01:00
parent 78df991399
commit f6709e90cd
Signed by: wneessen
GPG key ID: 385AC9889632126E
2 changed files with 9 additions and 8 deletions

8
msg.go
View file

@ -969,12 +969,12 @@ 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 false
}
// SendError returns the senderror field of the Msg
func (m *Msg) SendError() error {

View file

@ -5,6 +5,7 @@
package mail
import (
"errors"
"fmt"
"strconv"
"strings"
@ -94,12 +95,12 @@ 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 false
}
// String implements the Stringer interface for the SendErrReason
func (r SendErrReason) String() string {