Get the latest tech news

How we centralized and structured error handling in Golang


Handling errors in Go is simple and flexible – yet no structure! It’s supposed to be simple, right? Just return an error , wrapped with a message, and move on. Well, that simplicity quickly turns into chaotic as our codebase grows with more packages, more developers, and more “quick fixes” that stay there forever. Over time, the logs are full of “failed to do this” and “unexpected that”, and nobody knows if it’s the user’s fault, the server’s fault, buggy code, or it’s just a misalignment of the stars!

We decided to go with a structured, centralized system using namespace codes to make errors meaningful, traceable, and – most importantly – give us peace of mind! The real challenge starts when you have to bring it into a massive, living codebase where dozens of engineers are pushing changes daily, customers expect everything to work perfectly, and the system just can’t stop running. Centralized and structured namespace codes give us clarity, while tools for mapping, wrapping, and testing errors make our lives easier.

Get the Android app

Or read this on Hacker News

Read more on:

Photo of golang

golang

Photo of error handling

error handling

Related news:

News photo

Go Production Performance Gotcha – GOMAXPROCS

News photo

Lies we tell ourselves to keep using Golang (2022)

News photo

Hyrum’s Law in Golang