4 ms·
I don't get where is the bug in this code: http://talks.golang.org/2014/readability.slide#10 http://talks.golang.org/2014/readability.slide#10
by lukasm 12y ago
I don't get where is the bug in this code:
http://talks.golang.org/2014/readability.slide#10 http://talks.golang.org/2014/readability.slide#10
- _blob 12y agoIn the original code if out.Close() returns an error, run() will return nil. The revised code sets `err` to the returned error from out.Close(), in case the error from os.Create(*output) is nil. Simply spoken, the original code will suppress the error from out.Close().
- justinsb 12y agoWhat if the out.Write (which is presumably in "some code") has already set err? Then we lose _that_ error, if out.Close returns error. I think this is tricky in any language.