4 ms·
Right -- people already use defer as a way of mapping errors and doing cleanup in an already awful way: func something() (Err error) { defer func()
by cyphar 8y ago
Right -- people already use defer as a way of mapping errors and doing cleanup in an already awful way:
func something() (Err error) {
defer func() {
if Err != nil {
someCleanup()
Err = fmt.Errorf("wrapping: %v", Err)
}
}()
return blah()
}
And unlike handle you can actually give an arbitrary mapping function, while as far as I can tell you'd need to do something like
handle err { return mapError(err) }
Rather than the more ergonomic
handle mapError
Or
handle func(err Error) { return mapError(err) }
But whatever -- all of this is pretty useless. The main benefit of check in my mind is actually that you would be able to easily bump your test coverage -- because Go test coverage is based on lines and so the repeated use of
if err != nil {
return err
}
artificially dilutes your test coverage (you don't need to test that every error is propagated -- that's just doesn't make any sense and might not be possible if you are returning directly from os.* functions that don't even have fault-injection).