Perhaps something like this?
result := InvokeWithErrorLogger(
func (err error) { // Error handler
incrementMetric("foo")
log.Error("bar")
},
addTwoNumbers, a, b,
)
But the problem is that this approach is not better than just writing this, which doesn't need any new fancy addition to the language: result, err := addTwoNumbers(a, b)
if err != nil {
incrementMetric("foo")
log.Error("bar")
return fmt.Errorf("addTwoNumbers(%d, %d) = %v", a, b, err)
}
Hence why all the proposals ended up dying with the lack of traction.