4 ms·
Obviously I'm being terse for argument. You can easily imagine InvokeWithErrorLogger(fn, fnparam, log) or InvokeWithErrorAnnotator(fn, fnparam, annotato
by Pxtl 1y ago
Obviously I'm being terse for argument.
You can easily imagine
InvokeWithErrorLogger(fn, fnparam, log)
or
InvokeWithErrorAnnotator(fn, fnparam, annotatorFn)
Or any other common error-handling pattern.
- tail_exchange 1y agoPerhaps 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.