π»Go Error Handling Idioms
Stop writing `if err != nil` on autopilot. Learn why Go treats errors as values, then wrap, sentinel, and type them until you can design a clean error story for a small CLI.
Phase 1Errors as Values
See errors as values, not exceptions.
In Go, an error is a value β nothing more, nothing less
6 minIn Go, an error is a value β nothing more, nothing less
Any type with one method is an error
6 minAny type with one method is an error
The `if err != nil` ritual is the design, not a flaw
5 minThe `if err != nil` ritual is the design, not a flaw
Panic is for bugs, not for normal failure
6 minPanic is for bugs, not for normal failure
Phase 2Wrapping, Unwrapping, and Comparing
Wrap, unwrap, and compare errors in small programs.
`%w` adds context without hiding the original
6 min`%w` adds context without hiding the original
`errors.Unwrap` peels one layer at a time
5 min`errors.Unwrap` peels one layer at a time
Sentinels are singleton errors you compare against
6 minSentinels are singleton errors you compare against
`errors.Is` walks the chain; `==` does not
5 min`errors.Is` walks the chain; `==` does not
`errors.As` extracts a typed error out of any layer
6 min`errors.As` extracts a typed error out of any layer
Phase 3Choosing the Right Idiom
Choose sentinels, typed errors, errors.Is and errors.As.
Your reader is opening a file that doesn't exist
7 minYour reader is opening a file that doesn't exist
A user reports logs showing "EOF" with no stack of context
7 minA user reports logs showing "EOF" with no stack of context
Users ask: "which file couldn't you parse?"
7 minUsers ask: "which file couldn't you parse?"
Your CLI must exit non-zero on every real failure
7 minYour CLI must exit non-zero on every real failure
Phase 4Designing the CLI's Error Story
Design the error story for a small Go CLI.
Design the error handling for a small file-processing CLI
15 minDesign the error handling for a small file-processing CLI
Frequently asked questions
- Why doesn't Go use try/catch like other languages?
- This is covered in the βGo Error Handling Idiomsβ learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
- What is the difference between errors.Is and errors.As?
- This is covered in the βGo Error Handling Idiomsβ learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
- When should I use a sentinel error versus a typed error?
- This is covered in the βGo Error Handling Idiomsβ learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
- What does %w do in fmt.Errorf?
- This is covered in the βGo Error Handling Idiomsβ learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
- Is panic the Go version of throw?
- This is covered in the βGo Error Handling Idiomsβ learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Related paths
πPython Decorators Introduction
Build one mental model for Python decorators that covers closures, argument passing, functools.wraps, and stacking β then ship a working caching or logging decorator from scratch in under 30 lines.
π¦Rust Lifetimes Explained
Stop reading `'a` as line noise and start reading it as scope arithmetic β one failing snippet at a time β until you can thread lifetimes through a small parser or iterator adapter without fighting the borrow checker.
βΈοΈKubernetes Core Concepts
Stop drowning in 30+ resource types. Build the mental model one primitive at a time -- pods, deployments, services, ingress, config -- then deploy a real app with rolling updates and health checks.
πBig O Intuition
Stop treating Big O as math you memorized for an interview β build the intuition to spot O(nΒ²) disasters, pick the right data structure without thinking, and rewrite a slow function from O(nΒ²) to O(n) in under five minutes.