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.
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.
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.
Related concepts
- errorsimplemented by · errors is Go’s standard-library package for creating, wrapping, comparing, and inspecting error values.
- error chainuses · An error chain is a linked sequence of wrapped Go error values that preserves an underlying cause and added context.
- error handlingused by · Error handling is the practice of detecting, representing, propagating, reporting, and responding to errors or failures during software operation.
- pointeruses · A pointer is a value that refers to a memory location or another object, enabling indirect access to it.
- failureuses · A failure is an unsuccessful outcome or condition in which an operation, process, or system does not achieve an expected result.
- interfaceuses · A software interface is a contract or boundary that specifies the operations, properties, or capabilities through which types or components interact, without requiring a particular implementation.
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.



