Sentinel error

A package-level error value such as var ErrNotFound = errors.New("not found") that callers test for with errors.Is. Good when the caller only needs to know which kind of failure happened, not any details.

Minimal example

go
var ErrNotFound = errors.New("not found")

Learn this concept

Lesson 2.13 · Error classification in Go

Used in exercises

Exercise 2.14 · POST /v1/menu/price: price a configured item Exercise 2.22 · GET /v1/restaurants: signed cursors Exercise 3.22 · POST /v1/auth/refresh: detect token reuse Exercise 3.23 · Concurrent outbox relay Exercise 8.13 · Timestamped webhook signature package Exercise 8.15 · Latency percentile package
Prerequisite conceptsError wrapping