Errors - Golang - Complete Documentation by ntxm.org

Error Fundamentals in Go

The basics of Go errors - the error interface, returning and checking errors with if err != nil, and creating errors with errors.New and fmt.Errorf.

Wrapping and Inspecting Errors in Go

Add context to errors with %w, check them with errors.Is and errors.As, and return several at once with errors.Join.

Designing Errors in Go

Choose between sentinel errors and custom error types, decide when to panic instead of returning an error, and avoid the nil error interface trap.

Errors in Real Go Programs

The most common Go error handling mistakes with their exact messages, plus practical patterns for HTTP handlers and file reading.