sentinel error
A specific error value published in a package-level variable, such as io.EOF or os.ErrNotExist, that callers can test for with errors.Is.
In more detail
By convention the name starts with Err. Publishing one tells callers they may branch on it, for example use defaults when a config file is missing. Document which sentinel errors a function can return.
Example
var ErrBusy = errors.New("busy")Related terms
- errors.Is — The function that reports whether an error, or any error wrapped inside it, is a particular target error.
- errors.New — The function in Go's errors package that creates a simple error value with a fixed message.
- os.ErrNotExist — The sentinel error Go file functions return, wrapped, when a file or folder does not exist.
- error wrapping — Adding context to an error while keeping the original error inside it, so the message explains what failed and code can still test the cause.
Taught in
- Wrapping Errors and errors.Is — Concurrent Systems Programming with Go