Is there some idiomatic or well known way to deal with extra errors when 
you are already recovering from or reporting an error condition?

The typical case is, you hit an error and need to release resources before 
returning it. But the resources themselves may fail when closing them.

One (frequent) way seems to be to defer the freeing/closing so the resource 
will be freed on exit of the call no matter what. But that way you could be 
swallowing resource closing errors, which could lead to long debugging 
sessions in production.

Another way is to have an adhoc close & report wrapper function to use when 
deferring resource closing call that may fail. The wrapper can log the fact 
that a closing error happened while reporting some other error, then choose 
to return one or the other up the stack. But that can make the code ugly 
and difficult to read. Or is there a way to wrap 2 errors at once somehow?

Are there better ways to handle this situations?

Thanks,

Jose

-- 
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/dc0c90c8-dc34-4fbb-a11e-5b60ef860434n%40googlegroups.com.

Reply via email to