I've been playing around with reducing error handling boilerplate using
standard language constructs.
I'm currently doing something that looks like this:
import (
"github.com/michaelmacinnis/handle"
)
func do(name string) (err error) {
check, handle := handle.Errorf(&err, "do(%s)", name); defer handle()
s, err := works(name); check(err)
// ...
}
Other than the named return value and check being a hidden return, are
there reasons I would want to avoid doing this? I assume others have tried
similar things but I haven't stumbled across any similar packages.
Before using it in production I would probably want a linter that checks to
make sure that the statement after handle.Error or handle.Errorf is defer
blah, where blah is the name given to the second value returned by those
functions and that all of this happens at the start of a function.
Michael.
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/cbe53d07-4f99-49fa-a708-dcb85b1aff5bn%40googlegroups.com.