3 ms·
One pattern I happily use is to capture the error into a named return error, using a multi-error if the named error is already non-nil. func fetchFoo(ctx c
by sa46 4y ago
One pattern I happily use is to capture the error into a named return error, using a multi-error if the named error is already non-nil.
func fetchFoo(ctx context.Context) (_ Foo, mErr error) {
conn := pool.Acquire(ctx)
defer errs.Capture(&mErr, conn.Close, "close conn for fetch foo")
}
I have a couple of useful variants:
defer errs.CaptureLog(logger, conn.Close, "close conn")
defer errs.CaptureT(t, conn.Close, "close conn")