liveBook · Manning

Errors.As

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.

How 4 Manning books explain it

Learn Go with Pocket-Sized Projects

errors.As is a Go function that finds an error assignable to a target type and stores it through the supplied target pointer.

How it is used
Classifies returned errors so HTTP clients can detect timeouts and gRPC endpoints can select API status codes.
How deep it goes
Explains the Boolean result, target population, and pointer-to-pointer requirement, then applies type-specific methods and API mapping.
Examples
Demonstrates HTTP timeout detection and InvalidInputError translation in a gRPC CreateHabit endpoint.
What you can do after
Diagnose typed failures and route them to timeout handling or precise gRPC status responses.

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

Go by Example

errors.As is a Go standard-library function that searches an error chain for a value assignable to a specified error type and stores the result.

How it is used
Translates inspected driver and custom errors into meaningful application-level outcomes without exposing internal details.
How deep it goes
Explains chain extraction, target typing, pointer receivers, error-code inspection, and typed-nil custom-error pitfalls.
Examples
Uses SQLite primary-key code 1555, Shorten duplicate keys, ErrConflict, and a custom NotFoundError carrying an ID.
What you can do after
Apply it to extract concrete errors, inspect their details, and map them to stable application errors.

Read how Go by Example explains errors.As →

100 Go Mistakes and How to Avoid Them

errors.As is a Go standard-library function that recursively examines an error chain for an error assignable to a specified target type.

How it is used
Classifies wrapped errors so handlers can choose responses such as service-unavailable or bad-request status codes.
How deep it goes
Traces wrapping, recursive unwrapping, type matching, and the runtime panic caused by a non-pointer target.
Examples
Demonstrates transientError, database failure propagation, and HTTP response handling.
What you can do after
Diagnose/debug wrapped errors and route them according to their underlying type.

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

Go in Action, Second Edition

errors.As is a Go standard-library function that finds an error in an error chain assignable to a specified type and stores it in a destination value.

How it is used
Uses errors.As to recover typed error details when ordinary error messages or values do not provide enough information for handling.
How deep it goes
Explains error-chain matching, destination pointers, boolean results, and deferred handling, but does not detail the implementation internals.
Examples
Demonstrates recovering bulkGetError from BulkGet and using its missing keys to insert temporary store values.
What you can do after
Diagnose errors with errors.As by retrieving a matching typed value and acting on its additional data.

Read how Go in Action, Second Edition explains errors.As →

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.