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 wrapped errors in tests and exposes meaningful sentinel errors to package consumers.
How deep it goes
Explains error-chain matching and demonstrates wrapping a sentinel and checking it in table-driven tests.
Examples
Uses a word-guess validator and an exchange-rate client to illustrate wrapped and exposed sentinel errors.
What you can do after
Apply it via Go’s errors package to check expected errors even when contextual wrapping is present.

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 →

Also covered in

Related concepts

Questions about errors.Is

What is 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.

Which Manning books explain errors.Is?

Learn Go with Pocket-Sized Projects, Go by Example and 100 Go Mistakes and How to Avoid Them.

What is the difference between errors.Is and errors.As?

errors.Is is a Go standard-library function that reports whether an error or any error in its wrapping chain matches a target error. errors.As is a Go standard-library function that searches an error chain for a value assignable to a specified type and stores the result.

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.