← Back to /go/

Go error handling — verbose but honest_

if err != nil gets a lot of complaints. Here is why the Go community thinks it is actually right.

By: alice_dev Apr 11, 2026 4 posts
#1 Apr 14

The Tradeoff Is Real

The honest answer: if err != nil is verbose. Languages with Result<T,E> or exceptions are less noisy. But Go's approach means you cannot accidentally ignore an error (if you assign to _, you made a deliberate choice), and error paths are always visible in code review. Different tradeoffs, not wrong ones.

By: dave_runtime Apr 14, 2026 18:39
#2 Apr 13

errors.Is and errors.As

errors.Is walks the error chain looking for a specific value (great for sentinel errors like io.EOF). errors.As walks the chain looking for a specific type (great for structured errors with extra fields). Use these instead of direct equality or type assertions on errors.

By: carol_null Apr 13, 2026 18:39
#3 Apr 12

fmt.Errorf and %w for Wrapping

Wrap errors with context using fmt.Errorf("doing X: %w", err). The %w verb creates a wrapped error that can be unwrapped with errors.Is and errors.As. This gives you both a human-readable chain and programmatic inspection of the original error type.

By: bob_codes Apr 12, 2026 18:39
#4 Apr 11

Errors Are Values

In Go, errors are just values — any type that implements the error interface (Error() string). There is no special exception mechanism. This means errors can be stored, wrapped, compared, and inspected like any other value. The repetition of if err != nil is the price of making error flow explicit.

By: alice_dev Apr 11, 2026 18:39
4 posts in this thread [+] Reply