Errorf: support %w anywhere in the format string
Allow a single %w to appear anywhere in the format string, matched
by an operand that satisfies the error interface.
This is complicated by a few things:
- We don't want to do full-fledged printf verb parsing. We approximate,
and do not handle argument indexes on %w like "%w".
- There is a messy interaction with the xerrors formatting system (not
adopted in Go 1.13). When the %w is at the end we can control the
error string so that the wrapped error's message is formatted
properly, after the wrapping errors' message. With a %w in the
middle, we can't do that. In this CL, we print the wrapped error's
message twice: once in its place in the format string, and then
again because it's wrapped.
Reviewed-by: Damien Neil <email@example.com>
4 files changed