mirror of
https://github.com/mjl-/mox.git
synced 2025-07-13 00:54:38 +03:00
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:
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}()
|
||||
|
||||
|
Reference in New Issue
Block a user