Skip to content

Errors: resources

Level: 201 · anyone who wants the primary sources behind this chapter, and the book chapters that cover them

One line: Everything in this chapter is Go 1.13's %w, errors.Is, errors.As and errors.Unwrap, plus Go 1.20's errors.Join and multiple %w; the sources below are where those were specified, explained and argued over, and the book sections that teach them.

Primary sources

Books

  • Jon Bodner, Learning Go, 2nd ed. (O'Reilly, 2024), chapter 9, "Errors" — "How to Handle Errors: The Basics", "Use Strings for Simple Errors", "Sentinel Errors", "Errors Are Values", "Wrapping Errors", "Wrapping Multiple Errors", "Is and As", "Wrapping Errors with defer", "panic and recover", "Getting a Stack Trace from an Error". The most complete treatment on the shelf, and the only one that covers errors.Join.
  • Alan A. A. Donovan and Brian W. Kernighan, The Go Programming Language (Addison-Wesley, 2015), section 5.4, "Errors" — 5.4.1 "Error-Handling Strategies", 5.4.2 "End of File (EOF)" — section 7.8, "The error Interface", and section 7.11, "Discriminating Errors with Type Assertions". Written before %w: the strategies and the io.EOF discussion hold, the type assertions in 7.11 are what errors.As replaced.
  • Nathan Kozyra, Matt Butcher and Matt Farina, Go in Practice, 2nd ed. (Manning, 2025), chapter 4, "Handling errors and panics" — 4.1 "Error handling" (with "Nil best practices", "Custom error types" and "Error variables"), 4.2 "Wrapping errors", 4.3 "The panic system".
  • Adam Freeman, Pro Go (Apress, 2022), chapter 15, "Error Handling" — "Dealing with Recoverable Errors", "Generating Errors", "Reporting Errors via Channels", "Using the Error Convenience Functions", "Dealing with Unrecoverable Errors", "Recovering from Panics".
  • Miki Tebeka, Effective Go Recipes (Pragmatic Bookshelf, 2024), chapter 8, "Working with Errors" — Recipe 42 "Handling and Returning Errors", Recipe 45 "Checking Errors", Recipe 46 "Wrapping Errors" (an error type with Unwrap, and errors.Join collecting goroutine failures).
  • Katherine Cox-Buday, Concurrency in Go (O'Reilly, 2017), chapter 4, "Concurrency Patterns in Go" — the section "Error Handling": who should handle an error that a goroutine produced, and the result-plus-error struct sent on a channel.
  • Burak Serdar, Effective Concurrency in Go (Packt, 2023), chapter 6, "Error Handling" — "Error handling", "Pipelines", "Servers", "Panics": errors crossing goroutine boundaries.

Not on the shelf

  • Teiva Harsanyi, 100 Go Mistakes and How to Avoid Them (Manning, 2022) — its chapter on error management covers %w vs %v, comparing errors with ==, errors.As targets, and handling an error once; the mistakes are listed at 100go.co ↗.

Talks and videos

  • Marwan Sulaiman, Handling Go Errors ↗, GopherCon 2019 — programmable errors: designing error types so that the layers of a system can tell failures apart; slides ↗.
  • Dave Cheney, "Don't just check errors, handle them gracefully", GopherCon 2016 — the talk's text is his blog post of the same name ↗: sentinel errors, error types, opaque errors, and "handle an error once".

Read with care

  • Dave Cheney's post above ↗ and anything else built on github.com/pkg/errors ↗: the advice stands, but errors.Wrap is fmt.Errorf("…: %w", err) now, errors.Cause is a loop over errors.Unwrap, and the package is in maintenance mode — Errors: the compiler errors records what happens when the old names are typed.
  • The Go Programming Language, section 7.11 — a type switch on an error is correct only for an error that was never wrapped; after %w, errors.As.
  • Pre-1.20 advice that "Go has no way to hold several errors" and points at go.uber.org/multierr or hashicorp/go-multierror — errors.Join covers the common case, and both packages now build on it.
  • Any page that says errors.Is "compares error messages" — it compares values, and a message match is exactly what it does not do; %w wraps and errors.Is sees through it.
  • golang.org/x/xerrors — the prototype for Go 1.13; its %+v frames and xerrors.Errorf did not make it into the standard library, and the package says to use errors and fmt instead.

Checked 2026-09-23.