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.
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.
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
- sentinel erroruses · A sentinel error is a predefined error value with stable identity that represents a specific failure condition for programmatic comparison.
- errorsimplemented by · errors is Go’s standard-library package for creating, wrapping, comparing, and inspecting error values.
- error handlingused by · Error handling is the practice of detecting, representing, propagating, reporting, and responding to errors or failures during software operation.
- error chainuses · An error chain is a linked sequence of wrapped Go error values that preserves an underlying cause and added context.
- error wrappinguses · Error wrapping adds contextual information to an error while preserving access to the underlying error for later propagation or inspection.
- errors.Asalternative to · 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.


