[go-nuts] Re: defer func() { _ = resp.Body.Close() }()
Apologies for replying to an old post. But I am sometimes a bit slow in reading my messages. I too think that errcheck's is a bit severe in its treatment of deferred calls to Close(). So I forked the code and changed the behaviour to be more permissive. https://github.com/amnonbc/errcheck Feel free to use it. - amnon On Wednesday, 16 August 2017 13:05:39 UTC+1, Gert wrote: > > To pass errcheck I need to do something like > > defer func() { _ = resp.Body.Close() }() > > instead of > > defer resp.Body.Close() > > Is this something the errcheck tool can figure out to mark as valid > instead or does the errcheck tool need help from the compiler so the second > case is also ok? > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/0bcd5c8f-6b9a-4690-80c4-5cb5f71d3427o%40googlegroups.com.
[go-nuts] Re: defer func() { _ = resp.Body.Close() }()
Hi Gert, it the -ignore flag an option for you? E.g. errcheck -ignore '[cC]lose' $(GOPACKAGES) Cheers! Robert On Wednesday, 16 August 2017 14:05:39 UTC+2, Gert wrote: > > To pass errcheck I need to do something like > > defer func() { _ = resp.Body.Close() }() > > instead of > > defer resp.Body.Close() > > Is this something the errcheck tool can figure out to mark as valid > instead or does the errcheck tool need help from the compiler so the second > case is also ok? > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: defer func() { _ = resp.Body.Close() }()
Useful additional info: https://mijailovic.net/2017/05/09/error-handling-patterns-in-go/ https://groups.google.com/forum/#!topic/golang-nuts/-eo7navkp10 On Wednesday, August 16, 2017 at 3:05:39 PM UTC+3, Gert wrote: > > To pass errcheck I need to do something like > > defer func() { _ = resp.Body.Close() }() > > instead of > > defer resp.Body.Close() > > Is this something the errcheck tool can figure out to mark as valid > instead or does the errcheck tool need help from the compiler so the second > case is also ok? > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: defer func() { _ = resp.Body.Close() }()
For the truly paranoid, perhaps write a helper function "EnsureClosed()" or something like that, which will do the close, but perhaps also appropriately log a failure to close. On Wednesday, August 16, 2017 at 5:05:39 AM UTC-7, Gert wrote: > > To pass errcheck I need to do something like > > defer func() { _ = resp.Body.Close() }() > > instead of > > defer resp.Body.Close() > > Is this something the errcheck tool can figure out to mark as valid > instead or does the errcheck tool need help from the compiler so the second > case is also ok? > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: defer func() { _ = resp.Body.Close() }()
Never mind the tool is right I could print the error or something like that, I assumed you couldn't do anything useful with the error anyway in a defer On Wednesday, August 16, 2017 at 2:05:39 PM UTC+2, Gert wrote: > > To pass errcheck I need to do something like > > defer func() { _ = resp.Body.Close() }() > > instead of > > defer resp.Body.Close() > > Is this something the errcheck tool can figure out to mark as valid > instead or does the errcheck tool need help from the compiler so the second > case is also ok? > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.