What this thread does
Do first: run go vet -printf -errorsas ./..., then decide which underlying errors are part of your caller-facing contract.
Short answer
As of November 2026, use Go 1.27.4. %w wrapping adds context while preserving a cause for inspection. Wrapping exposes that cause as an API commitment; use ordinary text when callers must not depend on a dependency's specific errors (Go error design). Retryability is an application policy, not a property automatically supplied by wrapping.
Choose / don't choose
%w: choose when callers should inspect the underlying cause; don't expose storage/vendor errors accidentally.%v: choose human-readable context when intentionally hiding implementation details; don't expecterrors.Isorerrors.Asto recover an unwrapped cause (error design).- Typed retry contract: choose an explicitly documented interface implemented by your error types; don't infer retries from error text or assume every deadline failure is safe to replay.
Not for: HTTP timeout and runtime diagnostics; see go-setevent-errno-6-synctest-channel-and-http-timeout-errors.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
printf analyzer | Check Printf format strings and arguments | Current Go docs | vet |
errorsas analyzer | Report non-pointer or non-error values passed to errors.As; combine with printf to run both | Current Go docs | vet |
%w formatting verb | Error operand required; multiple %w operands wrap children in argument order | Current Go docs | Errorf |
As target | Non-nil pointer to an error-implementing type or any interface type | Current Go docs | As |
With no explicit analyzer flags, vet performs all its checks. Explicit true flags select only those checks; the two-analyzer command is a focused gate, not a replacement for a broader go vet ./... policy (vet).
Order of operations
1. At an owned error boundary, return nil on success and add useful operation context according to the API's error-exposure policy (Errorf). 2. Before retry classification, use errors.Is(err, context.Canceled). This follows wrapped causes; direct equality misses wrapping. Treat a match as cancellation other than deadline expiry and stop retries under this card's application policy (Is, cancellation sentinel). 3. Inspect an application-defined retry interface, for example:
var r interface{ Retryable() bool }
retry := errors.As(err, &r) && r.Retryable()
This interface name is illustrative, not a standard Go contract. Require replay safety, remaining deadline and bounded attempts separately. 4. As examines the outer error first, then each child's tree in pre-order depth-first order, returning the first match. With several causes, the first matching retry interface does not aggregate their decisions. Define precedence explicitly; do not make retry safety depend on accidental join order (As).
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
errors: target must be a non-nil pointer | Passing a nil target pointer instead of a pointer to a destination variable | Declare destination, then pass its address; for a pointer error type this is a pointer to pointer | independent target report, As |
| Wrapped cause no longer matches (symptom) | Text formatting with %v discards unwrap relationship | Use %w when cause exposure is intended; classify by Is/As | error design |
| Invalid %w operand (diagnostic) | Wrapping verb receives a value that does not implement error | Supply an error operand and retain printf analysis | Errorf, vet |
Missing
- No generic retry count, delay or retryable dependency error follows from the standard library. Domain semantics and idempotency determine the policy.
- A first-match As result does not resolve conflicting retry classifications in a multi-cause tree.
Checked
2026-11-12; Go release, errors/fmt/context/vet docs, the dated Go error-design article and target-pointer issue read. No analyzer or application commands executed.
Started from a post by @Go project, packaged by the editor. Original post