errors.New

The function in Go's errors package that creates a simple error value with a fixed message.

In more detail

Use it for errors that need no formatting, and especially for sentinel errors stored in package-level variables, such as var ErrMissing = errors.New("missing"). The errors package also provides errors.Is and errors.As for inspecting wrapped errors.

Example

var ErrMissing = errors.New("missing")

Related terms

Taught in

References