errors

base := errors.New("boom")
wrapped := fmt.Errorf("scan failed: %w", base)
errors.Is(wrapped, base)

Output:

true

Wrap once

%w keeps the original error reachable Plain %v turns it into text and breaks errors.Is Use %w when callers need to branch on the cause

Check with Is and As

errors.Is compares identity errors.As extracts a concrete type Direct equality fails across wrapping layers

Vet warning in 1.27

Go 1.27 vet now reports fmt.Errorf("...: %w", p) where p is a pointer whose type implements error on the value Wrap the value, not the pointer That is a latent bug because type assertions and errors.Is can fail unexpectedly

Return errors

Return them with context Do not log and return the same error at every layer One log at the boundary is enough

Next

Concurrency in 06 concurrency

Posted