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
- error — In Go, an ordinary value of the built-in error type that a function returns to report that something went wrong.
- 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.
- errors.Is — The function that reports whether an error, or any error wrapped inside it, is a particular target error.
- fmt.Errorf — The fmt function that creates an error with a formatted message, and wraps another error inside it when you use the %w verb.
Taught in
- Your First Program and go run — Concurrent Systems Programming with Go
- Wrapping Errors and errors.Is — Concurrent Systems Programming with Go
- Project Setup and Configuration — Concurrent Systems Programming with Go