mirror of
https://github.com/mjl-/mox.git
synced 2025-07-19 04:06:37 +03:00
check and log errors more often in deferred cleanup calls, and log remote-induced errors at lower priority
We normally check errors for all operations. But for some cleanup calls, eg "defer file.Close()", we didn't. Now we also check and log most of those. Partially because those errors can point to some mishandling or unexpected code paths (eg file unexpected already closed). And in part to make it easier to use "errcheck" to find the real missing error checks, there is too much noise now. The log.Check function can now be used unconditionally for checking and logging about errors. It adjusts the log level if the error is caused by a network connection being closed, or a context is canceled or its deadline reached, or a socket deadline is reached.
This commit is contained in:
@ -80,7 +80,7 @@ func (f *Filter) ensureBloom() error {
|
||||
return nil
|
||||
}
|
||||
var err error
|
||||
f.bloom, err = openBloom(f.bloomPath)
|
||||
f.bloom, err = openBloom(f.log, f.bloomPath)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -105,7 +105,8 @@ func (f *Filter) Close() error {
|
||||
err = f.Save()
|
||||
}
|
||||
if err != nil {
|
||||
f.db.Close()
|
||||
xerr := f.db.Close()
|
||||
f.log.Check(xerr, "closing junk filter after error")
|
||||
} else {
|
||||
err = f.db.Close()
|
||||
}
|
||||
@ -117,7 +118,7 @@ func OpenFilter(ctx context.Context, log mlog.Log, params Params, dbPath, bloomP
|
||||
var bloom *Bloom
|
||||
if loadBloom {
|
||||
var err error
|
||||
bloom, err = openBloom(bloomPath)
|
||||
bloom, err = openBloom(log, bloomPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -213,12 +214,12 @@ func NewFilter(ctx context.Context, log mlog.Log, params Params, dbPath, bloomPa
|
||||
|
||||
const bloomK = 10
|
||||
|
||||
func openBloom(path string) (*Bloom, error) {
|
||||
func openBloom(log mlog.Log, path string) (*Bloom, error) {
|
||||
buf, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("reading bloom file: %w", err)
|
||||
}
|
||||
return NewBloom(buf, bloomK)
|
||||
return NewBloom(log, buf, bloomK)
|
||||
}
|
||||
|
||||
func newDB(ctx context.Context, log mlog.Log, path string) (db *bstore.DB, rerr error) {
|
||||
|
Reference in New Issue
Block a user