Handle errors idiomatically in Go with wrapping and sentinels

8 steps · about 1 h 55 min · Intermediate

  1. Start from errors as values (article, The Go Blog, 15 min)

    Sets the mindset behind Go's if err != nil style.

  2. Wrap errors and inspect them (article, The Go Blog, 20 min)

    Introduces %w, errors.Is and errors.As.

  3. Read the errors package reference (article, pkg.go.dev, 15 min)

    Gives exact semantics for Is, As, Join and Unwrap.

  4. See basic errors by example (article, Go by Example, 10 min)

    Shows sentinel and custom error code compactly.

  5. Write a custom error type (article, Go by Example, 10 min)

    Adds structured fields to an error.

  6. Know when panic and recover apply (article, The Go Blog, 20 min)

    Clarifies the rare cases where panic is acceptable.

  7. Recover from a panic by example (article, Go by Example, 10 min)

    Shows the rare recover pattern in a few lines.

  8. Design APIs that cut error boilerplate (article, The Go Blog, 15 min)

    Shows patterns that reduce repeated checks.