Re: [go-nuts] Re: Deferring a close that can fail

2019-03-21 Thread roger peppe
On Thu, 21 Mar 2019 at 16:14, wrote: > Two things to note about this. > > First, if the "everything else" deferred to might include a return > statement, then this could result in the same "silent failure" behavior. > Yup, don't do that :) > Secondly - use this pattern with great caution. It i

Re: [go-nuts] Re: Deferring a close that can fail

2019-03-21 Thread jake6502
Two things to note about this. First, if the "everything else" deferred to might include a return statement, then this could result in the same "silent failure" behavior. Secondly - use this pattern with great caution. It is critical to confirm that a double close on ifDB is explicitly allowed

Re: [go-nuts] Re: Deferring a close that can fail

2019-03-21 Thread roger peppe
This issue is why I like having idempotent close. Do: defer ifDB.Close() but also, after everything else is complete, do: if err := ifDB.Close(); err != nil { handle error case } That way if you return early on error your connection is still closed, but you can still write th

Re: [go-nuts] Re: Deferring a close that can fail

2019-03-20 Thread David Collier-Brown
Hmmn, Donald Knuth would not have liked this (;-)) Knuthput, if I remember correctly, didn't have "fail on close()" semantics. > > --dave -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails fr

Re: [go-nuts] Re: Deferring a close that can fail

2019-03-20 Thread David Collier-Brown
Looks as if "Close()-like things" all fall into two categories - the usual horrid one, in which you can discover too late something didn't complete, or - the trivial case, in which the pre-close operations are transactional and xxx.Close() only ever returns nil Which means I have to

Re: [go-nuts] Re: Deferring a close that can fail

2019-03-20 Thread Manlio Perillo
On Wednesday, March 20, 2019 at 10:53:44 PM UTC+1, Kurtis Rader wrote: > > On Wed, Mar 20, 2019 at 2:08 PM Manlio Perillo > wrote: > >> Note from the Linux close documentation: >> >> Not checking the return value of close() is a common but nevertheless >> serious programming error. It is quite po

Re: [go-nuts] Re: Deferring a close that can fail

2019-03-20 Thread Kurtis Rader
On Wed, Mar 20, 2019 at 2:08 PM Manlio Perillo wrote: > Note from the Linux close documentation: > > Not checking the return value of close() is a common but nevertheless > serious programming error. It is quite possible that errors on a previous > write (2) ope