Error Handling in Go: Error Values, Wrapping, errors.Is/As/AsType and panic
In Go an error is a return value: sentinel errors are recognised with errors.Is, custom error types with errors.As or Go 1.26's errors.AsType, and %w adds context while keeping the chain. ErrOutOfStock and ValidationError in Bookstore, collecting validation problems with errors.Join, the trap of wrapping a pointer error with %w and the Go 1.27 vet check that catches it, mapping errors to 404, a handler panic producing an empty reply, and a recover middleware.
15 Nov 2026
·
15 min
·
4