Sentinel error
A sentinel error is a predefined error value with stable identity that represents a specific failure condition for programmatic comparison.
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
- errors.Isused by · errors.Is is a Go standard-library function that reports whether an error or any error in its wrapping chain matches a target error.
- error variableequivalent to · An error variable is a package-scoped Go variable whose value identifies a particular error condition and can be compared or returned by Go code.
- error valuekind of · An error value is a value representing a failure condition that an operation or function can return.
- failurecontrasts with · A failure is an unsuccessful outcome or condition in which an operation, process, or system does not achieve an expected result.
- error handlinguses · Error handling is the practice of detecting, representing, propagating, reporting, and responding to errors or failures during software operation.
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.


