News for hackers. Stuff that matters.
Re:Maybe adding generics to Go is about syntax after all by cyphar on Tuesday September 04, 2018 @12:07PM (#17910037)
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).

There are no comments on this comment yet.