Go custom errors: wrap with %w, check with Is and As

11 steps · about 3 h 15 min · Intermediate

  1. Go by Example: Errors (tutorial, Go by Example, 10 min)

    Start with the basics of returning and checking errors and a first look at sentinel errors.

  2. Error handling and Go (article, The Go Blog, 15 min)

    It explains the error interface and why errors are plain values, which custom types build on.

  3. Errors are values (article, The Go Blog, 10 min)

    Rob Pike's post gives the mindset behind designing your own error types.

  4. Working with Errors in Go 1.13 (article, The Go Blog, 25 min)

    This is the authoritative explanation of %w, Unwrap, errors.Is and errors.As from the Go team.

  5. Runnable Go Docs: Custom Errors (doc, Coddy, 20 min)

    It has runnable examples of sentinel errors, error types, wrapping with %w, and Unwrap and Is methods.

  6. Module 8: Error Handling: Idiomatic Patterns (tutorial, Tobias Weiss, 25 min)

    It covers the common mistake of leaving out Unwrap, with check questions to test yourself.

  7. Errors in Go: Wrapping, errors.Is, errors.As, panic and recover (article, Teach YourSelf Coding, 20 min)

    It gives a decision table for when to use plain, typed or joined errors, and introduces Go 1.26's errors.AsType.

  8. Errors in Go: errors.Is, errors.As, Wrapping, and Sentinel Errors (article, HunCoding, 20 min)

    It shows the full pattern in a repository and service layer, mapping errors to HTTP status codes.

  9. Custom Errors and Error Wrapping in Go (article, Calmops, 20 min)

    It covers advanced designs, such as a custom type that also matches a sentinel through an Is method.

  10. Fix: Go Error Handling Not Working — errors.Is, errors.As, and Wrapping (article, FixDevs, 15 min)

    It covers the usual bugs: using %v instead of %w, pointer-receiver mismatches and a missing Unwrap.

  11. errors package - errors - Go Packages (reference, Go standard library, 15 min)

    Finish with the official reference for Is, As, AsType, Join and the Unwrap rules.