errors.Is

The function that reports whether an error, or any error wrapped inside it, is a particular target error.

In more detail

Use errors.Is(err, os.ErrNotExist) instead of comparing message text, which breaks as soon as someone rewords a message. errors.As does the same search but looks for an error of a given type and extracts it.

Example

if errors.Is(err, ErrMissing) {
	fmt.Println("use defaults")
}

Related terms

Taught in

References