aboutsummaryrefslogtreecommitdiffstats
path: root/worker/lib/parse.go
diff options
context:
space:
mode:
authorMoritz Poldrack <git@moritz.sh>2022-07-31 15:15:27 +0200
committerRobin Jarry <robin@jarry.cc>2022-08-04 21:58:04 +0200
commit70bfcfef42578079f211d87cddc49519ee3503dc (patch)
treeae35c38e3980c73af2b43be10fe8cc9ece4f3f9a /worker/lib/parse.go
parent978d35d356e8752bdd272884df48a6289d88b40a (diff)
downloadaerc-70bfcfef42578079f211d87cddc49519ee3503dc.tar.gz
lint: work nicely with wrapped errors (errorlint)
Error wrapping as introduced in Go 1.13 adds some additional logic to use for comparing errors and adding information to it. Signed-off-by: Moritz Poldrack <moritz@poldrack.dev> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'worker/lib/parse.go')
-rw-r--r--worker/lib/parse.go26
1 files changed, 13 insertions, 13 deletions
diff --git a/worker/lib/parse.go b/worker/lib/parse.go
index d92eeda7..ad5e0a8b 100644
--- a/worker/lib/parse.go
+++ b/worker/lib/parse.go
@@ -104,7 +104,7 @@ func ParseEntityStructure(e *message.Entity) (*models.BodyStructure, error) {
if cd := e.Header.Get("content-disposition"); cd != "" {
contentDisposition, cdParams, err := e.Header.ContentDisposition()
if err != nil {
- return nil, fmt.Errorf("could not parse content disposition: %v", err)
+ return nil, fmt.Errorf("could not parse content disposition: %w", err)
}
body.Disposition = contentDisposition
body.DispositionParams = cdParams
@@ -113,7 +113,7 @@ func ParseEntityStructure(e *message.Entity) (*models.BodyStructure, error) {
if mpr := e.MultipartReader(); mpr != nil {
for {
part, err := mpr.NextPart()
- if err == io.EOF {
+ if errors.Is(err, io.EOF) {
return &body, nil
} else if err != nil {
return nil, err
@@ -133,27 +133,27 @@ var DateParseError = errors.New("date parsing failed")
func parseEnvelope(h *mail.Header) (*models.Envelope, error) {
from, err := parseAddressList(h, "from")
if err != nil {
- return nil, fmt.Errorf("could not read from address: %v", err)
+ return nil, fmt.Errorf("could not read from address: %w", err)
}
to, err := parseAddressList(h, "to")
if err != nil {
- return nil, fmt.Errorf("could not read to address: %v", err)
+ return nil, fmt.Errorf("could not read to address: %w", err)
}
cc, err := parseAddressList(h, "cc")
if err != nil {
- return nil, fmt.Errorf("could not read cc address: %v", err)
+ return nil, fmt.Errorf("could not read cc address: %w", err)
}
bcc, err := parseAddressList(h, "bcc")
if err != nil {
- return nil, fmt.Errorf("could not read bcc address: %v", err)
+ return nil, fmt.Errorf("could not read bcc address: %w", err)
}
replyTo, err := parseAddressList(h, "reply-to")
if err != nil {
- return nil, fmt.Errorf("could not read reply-to address: %v", err)
+ return nil, fmt.Errorf("could not read reply-to address: %w", err)
}
subj, err := h.Subject()
if err != nil {
- return nil, fmt.Errorf("could not read subject: %v", err)
+ return nil, fmt.Errorf("could not read subject: %w", err)
}
msgID, err := h.MessageID()
if err != nil {
@@ -167,7 +167,7 @@ func parseEnvelope(h *mail.Header) (*models.Envelope, error) {
if err != nil {
// still return a valid struct plus a sentinel date parsing error
// if only the date parsing failed
- err = fmt.Errorf("%w: %v", DateParseError, err)
+ err = fmt.Errorf("%v: %w", DateParseError, err)
}
return &models.Envelope{
Date: date,
@@ -217,7 +217,7 @@ func parseDate(h *mail.Header) (time.Time, error) {
func parseReceivedHeader(h *mail.Header) (time.Time, error) {
guess, err := h.Text("received")
if err != nil {
- return time.Time{}, fmt.Errorf("received header not parseable: %v",
+ return time.Time{}, fmt.Errorf("received header not parseable: %w",
err)
}
return time.Parse(time.RFC1123Z, dateRe.FindString(guess))
@@ -254,18 +254,18 @@ func MessageInfo(raw RawMessage) (*models.MessageInfo, error) {
defer r.Close()
msg, err := message.Read(r)
if err != nil {
- return nil, fmt.Errorf("could not read message: %v", err)
+ return nil, fmt.Errorf("could not read message: %w", err)
}
bs, err := ParseEntityStructure(msg)
if errors.As(err, new(message.UnknownEncodingError)) {
parseErr = err
} else if err != nil {
- return nil, fmt.Errorf("could not get structure: %v", err)
+ return nil, fmt.Errorf("could not get structure: %w", err)
}
h := &mail.Header{Header: msg.Header}
env, err := parseEnvelope(h)
if err != nil && !errors.Is(err, DateParseError) {
- return nil, fmt.Errorf("could not parse envelope: %v", err)
+ return nil, fmt.Errorf("could not parse envelope: %w", err)
// if only the date parsing failed we still get the rest of the
// envelop structure in a valid state.
// Date parsing errors are fairly common and it's better to be