3 ms·
Yes, that's attrocious, but the complaints come from higher functions, which only rarely modify the error in a meaningful way. db, err := openConnection(..
by tgv 4y ago
Yes, that's attrocious, but the complaints come from higher functions, which only rarely modify the error in a meaningful way.
db, err := openConnection(...)
if err != nil {
return ..., err
}
And then elsewhere you call the function that contains that snippet, and return the error again.
I think the entire issue is that it looks too much like boilerplate. My preferred solution would be some operator that has sufficient expressiveness. After all, you should not only return an error, but there almost always are other return arguments as well, and sometimes another error should be returned, so it would look like this
db := openConnection(...) ~> {
error handling
}
In case of auto-zeroed or named return values, a simple ~> return would suffice.
But that's really not much better than the current situation. Go's syntax just resists functional solutions. Better leave it the way it is. In Go 1, certainly.