Error type
An error type is a data type whose values represent failure conditions and may carry information or behavior for reporting and handling those failures.
Refactoring to Rust
A custom error type is a programmer-defined type that represents the distinct failure conditions an operation can return.
- How it is used
- Represents distinct operation failures so callers can handle them separately or deliberately propagate them.
- How deep it goes
- Works from a single enum variant through calculator parsing and stack failures to propagation and public API visibility; defers error formatting implementation.
- Examples
- Uses negative FizzBuzz input, invalid calculator numbers, an empty stack, and a compiler error for a private return type.
- What you can do after
- Build it from scratch: define error variants, return them in `Result`, propagate them with `?`, and expose the type when required.
Rust Servers, Services, and Apps
A custom error type is a programmer-defined Rust type that represents application-specific failures and can unify multiple underlying error types.
- How it is used
- Unifies failures across database access and web handlers so Actix can return meaningful HTTP errors.
- How deep it goes
- Works through enum variants, From conversions, ResponseError status and body methods, and handler return types.
- Examples
- Uses a parsing-and-file-I/O mismatch, a course-insertion handler, and a registration error enum.
- What you can do after
- Build it from scratch for an Actix service, propagate database failures, and return category-appropriate HTTP responses.
Read how Rust Servers, Services, and Apps explains error type →
Go in Action, Second Edition
An error type is Go's interface type for representing failed or abnormal operation results through an Error method.
- How it is used
- Makes failures from key/value store operations explicit in function return values.
- How deep it goes
- Defines the one-method interface and works through a slice-backed custom error, without descending below interface behavior.
- Examples
- Uses key/value store operations and a bulk lookup that collects missing keys in a custom error.
- What you can do after
- Build it from scratch by implementing Error() string on a custom type and returning it when a bulk lookup finds missing keys.
Learn Go with Pocket-Sized Projects
A custom error is an application-defined error value or type representing a specific failure condition.
- How it is used
- Uses typed and custom errors to carry domain failures across business, repository, and gRPC API layers.
- How deep it goes
- Defines error fields and Error methods, demonstrates validation and status conversion, and tests ErrorAs without exploring broader error hierarchies.
- Examples
- Uses InvalidInputError for blank habit names and a not-found repository error when ticking an unknown habit.
- What you can do after
- Apply it via Go error types, errors.Is, ErrorAs, and gRPC status conversion to validate inputs and expose stable failures.
Read how Learn Go with Pocket-Sized Projects explains error type →
Go in Practice, Second Edition
- How it is used
- Uses custom error types to preserve failure details and let callers choose handling based on the specific error.
- How deep it goes
- Explains the error interface, implements structured parser and HTTP errors, and stops short of broader type-system internals.
- Examples
- Demonstrates ParseError diagnostics and conversion of non-success HTTP responses into structured errors.
- What you can do after
- Build custom Go errors that carry structured diagnostics and handle unexpected HTTP responses explicitly.
Read how Go in Practice, Second Edition explains error type →
Related concepts
- failureimplements · A failure is an unsuccessful outcome or condition in which an operation, process, or system does not achieve an expected result.
- ResponseErrorimplements · ResponseError is an Actix Web trait that defines how an application error is converted into an HTTP response and status code.
- From traitused by · From is Rust’s standard-library trait for infallibly converting a value of one type into another type.
- Errorimplements · std::error::Error is Rust’s standard-library trait for types that represent errors and can provide descriptions and source-error relationships.
- responseproduces · An HTTP response is a protocol-formatted message a server sends to a client in reply to a request.
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.




