liveBook · Manning

Errors

As explained in Learn Go with Pocket-Sized Projects

The errors package is Go's standard-library package for creating, wrapping, comparing, and inspecting error values.

Go's errors package supports comparing and inspecting errors while keeping caller behavior independent of exact error messages. errors.As reports whether an error can be assigned to a target type and, when successful, stores the matching value there. section 6.6.2

Parsing with recognizable errors

A money package can expose ErrInvalidDecimal and ErrTooLarge as typed domain errors. ParseDecimal wraps the underlying strconv.ParseInt failure with ErrInvalidDecimal, while callers can compare the resulting error without relying on its complete message.

How Learn Go with Pocket-Sized Projects covers it

How deep it goes
Explains custom error types, wrapping, errors.As targets, and errors.Is tests through runnable parsing and HTTP examples.
Examples
Uses malformed decimals, oversized quantities, wrapped ParseInt failures, and delayed HTTP test servers to demonstrate inspection.
What it assumes
Assumes familiarity with Go functions, pointers, interfaces, HTTP clients, and table-driven tests.
What you can do after
Diagnose/debug with it by classifying domain errors, extracting typed causes, detecting timeouts, and testing errors through errors.Is.
How it connects
Connects error handling with parsing, error wrapping, sentinel errors, HTTP clients, URL errors, and timeouts.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Go with Pocket-Sized Projects. The section links point to the parts of the book it draws on.