in store/, change functions from calling panic to returning errors

this is a library package, errors should be explicit. callers had to be careful
when calling these "X" functions. now it's explicit.
This commit is contained in:
Mechiel Lukkien
2023-04-20 14:16:56 +02:00
parent 936a0d5afe
commit 08eb1a5472
9 changed files with 173 additions and 165 deletions

View File

@ -2,6 +2,7 @@ package smtpserver
import (
"context"
"fmt"
"net"
"os"
"time"
@ -172,7 +173,10 @@ func analyze(ctx context.Context, log *mlog.Log, resolver dns.Resolver, d delive
if rs != nil {
mailbox = rs.Mailbox
}
mb := d.acc.MailboxFindX(tx, mailbox)
mb, err := d.acc.MailboxFind(tx, mailbox)
if err != nil {
return fmt.Errorf("finding destination mailbox: %w", err)
}
if mb != nil {
// We want to deliver to mb.ID, but this message may be rejected and sent to the
// Rejects mailbox instead, which MailboxID overwritten. Record the ID in
@ -187,7 +191,6 @@ func analyze(ctx context.Context, log *mlog.Log, resolver dns.Resolver, d delive
log.Debug("mailbox not found in database", mlog.Field("mailbox", mailbox))
}
var err error
isjunk, conclusive, method, err = reputation(tx, log, d.m)
reason = string(method)
return err

View File

@ -577,7 +577,7 @@ func serve(listenerName string, cid int64, hostname dns.Domain, tlsConfig *tls.C
} else if err, ok := x.(error); ok && isClosed(err) {
c.log.Infox("connection closed", err)
} else {
c.log.Error("unhandled error", mlog.Field("err", x))
c.log.Error("unhandled panic", mlog.Field("err", x))
debug.PrintStack()
metrics.PanicInc("smtpserver")
}
@ -679,7 +679,7 @@ func command(c *conn) {
} else {
// Other type of panic, we pass it on, aborting the connection.
c.log.Errorx("command panic", err)
panic(x)
panic(err)
}
}()