Structured Errors in Go (2022)
Published on: 2025-06-11 09:54:24
Structured errors in Go Bridge the gap between structured logging and errors in Go written almost 3 years ago
This post documents a catalogue of experiments on the topic of error management in medium-sized Go programs, specifically HTTP APIs, with certain end goals in mind around ergonomics, syntactic salt and making the lives of everyone involved easier. The final result is a simple approach and a new library that I've been using in production for a couple of months now.
Error handling (or, more accurately, error management) has always ended up being a hot topic with Go. Most likely because of two things. Firstly, Go's early ideas about error handling – as with a lot of Go's design – chose to steer away from commonly found implementations such as exception handling and opted for a vastly simpler (at least from an implementation perspective) approach: return values. Secondly, the smallest, simplest form of an error in Go is a string of text. This leaves a lot of room for building on
... Read full article.