liveBook · Manning

Sentinel error

A sentinel error is a predefined error value with stable identity that represents a specific failure condition for programmatic comparison.

How 3 Manning books explain it

Learn Go with Pocket-Sized Projects

A sentinel error is a predefined error value or type that callers can compare or check to identify a specific domain condition.

How it is used
Exposes domain conditions that other packages can recognize without coupling consumers to implementation-specific errors.
How deep it goes
Defines the custom type, return sites, wrapping, and tests, but stops short of broader error-taxonomy design.
Examples
Uses empty-corpus detection, ReadCorpus, ErrCorpusIsEmpty, ErrCallingServer, and table-driven tests.
What you can do after
Build it from scratch and apply it via errors.Is to expose stable, package-specific failure conditions.

Read how Learn Go with Pocket-Sized Projects explains sentinel error →

Go in Action, Second Edition

A sentinel error is a predefined error value identified by comparison so callers can make programmatic decisions about a failure condition.

How it is used
Uses stable package-level values to let callers branch on common failure conditions.
How deep it goes
Explains declaration, return, errors.Is checks, wrapping, and the point where custom error types carry extra data.
Examples
Uses KVStore operations, ErrConflict, ErrNotExist, io.EOF, ForcePut, and bulk retrieval of missing keys.
What you can do after
Apply it via errors.Is to recognize known conditions, including conditions preserved inside wrapped errors.

Read how Go in Action, Second Edition explains sentinel error →

100 Go Mistakes and How to Avoid Them

An error sentinel is a predefined error value representing a known condition that callers can compare against.

How it is used
Guides expected-error design and reliable caller checks in Go error handling.
How deep it goes
Explains declaration, expected-versus-unexpected classification, direct comparison, and wrapped-error checks.
Examples
Uses ErrFoo, sql.ErrNoRows, io.EOF, query handling, and direct versus wrapped comparisons.
What you can do after
Diagnose/debug with it by distinguishing expected conditions and checking sentinels correctly through wrapped errors.

Read how 100 Go Mistakes and How to Avoid Them explains sentinel error →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.