4 ms·
Go does absolutely nothing to ensure you handle the error. The only thing in Go source code that you see more often than the boiler plate "if err != nil" is "a
by hota_mazi 7y ago
Go does absolutely nothing to ensure you handle the error.
The only thing in Go source code that you see more often than the boiler plate "if err != nil" is "a, _ = foo()".
It's all too easy to ignore an error in Go.
- Sphax 7y ago> The only thing in Go source code that you see more often than the boiler plate "if err != nil" is "a, _ = foo()". Where did you see that ? because that's not been my experience at all, and I've looked at a lot of Go code.
- shazow 7y ago> Go does absolutely nothing to ensure you handle the error. Go has many community linters available, https://github.com/kisielk/errcheck https://github.com/kisielk/errcheck is popular for checking unhandled errors. If you'd like a combo-pack, check out https://github.com/golangci/golangci-lint https://github.com/golangci/golangci-lint which includes all of the popular linters in a configurable way.
- apta 7y agoThose linters won't catch everything. There are cases that will slip by. Rust's error handling, as well as exceptions are both strictly superior to golang's error handling.
- Thaxll 7y agoThis is fud, I've never seen in Go code people dropping the err with _. The reason why you don't see that is because you have to be explicit about that, it's not something you forget it's done on purpose which obviously no one does.
- apta 7y agoJust because you haven't seen it doesn't mean it doesn't exist. It's very easy to mishandle errors in golang, I've seen it several times now.