liveBook · Manning

Errors.Is

errors.Is is a Go standard-library function that reports whether an error or any error in its wrapping chain matches a target error.

How 3 Manning books explain it

Learn Go with Pocket-Sized Projects

errors.Is is a Go standard-library function that reports whether an error matches a target error through direct or wrapped identity.

How it is used
Checks whether returned errors match expected sentinels in tests and at package boundaries.
How deep it goes
Defines chain matching and demonstrates wrapped-error assertions, without detailing a custom matching implementation.
Examples
Uses a word-length validation test, decimal parsing errors, and caller-facing HTTP errors.
What you can do after
Apply it via Go’s errors package to test wrapped sentinels and recognize package-level errors.

Read how Learn Go with Pocket-Sized Projects explains errors.Is →

Go by Example

errors.Is is a Go standard-library function that reports whether an error or any error in its wrapping chain matches a target error.

How it is used
Distinguishes specific failures after CLI parsers and services wrap errors with contextual messages.
How deep it goes
Explains chain matching through %w-based wrapping and contrasts it with failing direct equality.
Examples
Uses wrapped strconv.ErrSyntax in a flag parser and wrapped ErrBadRequest in an in-memory link service.
What you can do after
Apply it via the standard library to branch on wrapped sentinel errors without discarding context.

Read how Go by Example explains errors.Is →

100 Go Mistakes and How to Avoid Them

errors.Is is a Go standard-library function that reports whether an error chain contains a specified error value or matches it according to an Is method.

How it is used
Checks whether an error represents a specified sentinel value while preserving matching through wrapped error context.
How deep it goes
Explains the equality failure, shows corrected Go code, and describes recursive unwrapping through the error chain.
Examples
Contrasts == and errors.Is when checking sql.ErrNoRows returned by a query.
What you can do after
Diagnose failed sentinel checks and replace equality with errors.Is when returned errors may be wrapped.

Read how 100 Go Mistakes and How to Avoid Them explains errors.Is →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.