Dmitrii Aleksandrov

Go Didn't Get Error Handling Right

Posted on 2 mins

Error Handling Tech

I’ve finally found a way to put this concisely:

No, Go didn’t get this right. Returning a tuple (a T and an error) isn’t an appropriate tool when you want your function to return either a T or an error. It’s a brittle hack that requires everyone to use a third-party linter on top. Otherwise, that tuple is handled incorrectly too frequently.

All of that, because Go keeps ignoring a basic feature from the 1970s that allows to you express the “or” relationships (and nullability).

APIs that are easy to use incorrectly are bad APIs.

Appendix

To be clear:


Other people’s posts:

My other posts about error handling:

  1. “Rust Solves The Issues With Exceptions”
  2. “Why Use Structured Errors in Rust Applications?”
  3. “Go Didn’t Get Error Handling Right”

Discuss

Comments