A common mistake is replacing %w with %v while assuming callers can still inspect the original error. %v converts the error to text and adds context, but the source error is no longer available for unwrapping. section 7.2
Convert instead of wrap
if err != nil { return fmt.Errorf("bar failed: %v", err) } The message retains information about the failure, but callers cannot unwrap the returned error or check whether the source was a particular error type or value. section 7.2
Use %v when the underlying error is an implementation detail and should not become part of the caller-facing contract. Use %w when callers should inspect or unwrap the source error. section 7.2
if err != nil {
return fmt.Errorf("bar failed: %v", err)
}
Inspect the concrete fmt.Errorf call that converts an error with %v. section 7.2
