4 ms·
I'm a Go developer, but I don't buy this. At best it's showing how, with a bit of work (often times by the developer), errors aren't that bad. But I don't see h
by latch 12y ago
I'm a Go developer, but I don't buy this. At best it's showing how, with a bit of work (often times by the developer), errors aren't that bad. But I don't see how it's showing that it's better?
If you log the error when checking if ew.err != nil, which might be many lines or even a different function, you'll have a hard time getting a meaningful context (which is hard to do in Go in the best case), like a stack.
- axman6 12y agoOne way I could see to make this more generic is to provide the errWriter strict with a function to call on the error if it's not nil, but i'm not familiar enough with Go to know how we'll thug might work.
- enneff 12y agoThe point is not to use this exact pattern, but to write code to handle errors in a way that works in your context. If the error check is many lines away or in a different function, you should use a different approach.