Table of Contents

Sentinel errors

What is it?

A sentinel error is a package-level variable used as a fixed, recognizable error value.

Example:

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

What is it used for?

or (preferably) `errors.Is(err, ErrNotFound)` when wrapping is involved.

Example

package store
 
import "errors"
 
var ErrNotFound = errors.New("not found")

Notes / pitfalls

Hard words (English)