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¶
- Package
errors↗ — the definition of wrapping (Unwrap() error,Unwrap() []error), the tree thatIsandAswalk, and theIs/Asmethods a type may add;fmt.Errorf↗ —%w, and what more than one%wreturns. - Working with Errors in Go 1.13 ↗, the Go blog — the "Whether to Wrap" section is the one to read twice; it settles that wrapping is an API decision.
- Errors are values ↗, Rob Pike (2015) — why
if err != nilis not the whole story, and theerrWriterpattern for checking once at the end. - Error handling and Go ↗, Andrew Gerrand (2011) — the original explanation of
erroras an interface and of custom error types. - Error Values ↗, the design document, and proposal #29934 ↗ — where
%w,IsandAswere designed, and what was dropped on the way (thexerrorsframe and formatting parts). - The Go 1.13 release notes ↗ and the Go 1.20 release notes ↗ — the two releases this chapter measures.
- The Error Value FAQ ↗ on the Go wiki — how to migrate
==and type assertions, and how a package that returns wrapped errors should document them. - Code Review Comments: Error Strings ↗ and Effective Go: Errors ↗ — the message conventions.
- The source, for the exact panics and formats:
errors/wrap.go↗,errors/join.go↗,fmt/errors.go↗, all at go1.25.5. - The
go vetanalyzers this chapter runs:printf↗,errorsas↗,unusedresult↗,stdmethods↗.
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 theio.EOFdiscussion hold, the type assertions in 7.11 are whaterrors.Asreplaced. - 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, anderrors.Joincollecting 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
%wvs%v, comparing errors with==,errors.Astargets, 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, buterrors.Wrapisfmt.Errorf("…: %w", err)now,errors.Causeis a loop overerrors.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/multierrorhashicorp/go-multierror—errors.Joincovers 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;%wwraps anderrors.Issees through it. golang.org/x/xerrors— the prototype for Go 1.13; its%+vframes andxerrors.Errorfdid not make it into the standard library, and the package says to useerrorsandfmtinstead.
Checked 2026-09-23.