Skip to main content

Command Palette

Search for a command to run...

Pragmatic Error Handling in Go

Updated
•1 min read•View as Markdown
Y
Backend engineer specializing in Go, Rust, and TypeScript. Writing about production patterns, performance optimization, and developer tooling.

Pragmatic Error Handling in Go

Beyond if err != nil - techniques that work.

Always Wrap

return fmt.Errorf("get order %s: %w", id, err)

Sentinels

var ErrNotFound = errors.New("not found")

HTTP Pattern

type HandlerFunc func(w http.ResponseWriter, r *http.Request) error

errgroup

g, ctx := errgroup.WithContext(ctx)
g.Go(func() error { return fn() })

If this was helpful, you can support my work at ko-fi.com/nopkt

3 views

More from this blog

Production Backend Patterns

22 posts