const percentBangString … // Errorf formats according to a format specifier and returns the string as a // value that satisfies error. // // The returned error includes the file and line number of the caller when // formatted with additional detail enabled. If the last argument is an error // the returned error's Format method will return it if the format string ends // with ": %s", ": %v", or ": %w". If the last argument is an error and the // format string ends with ": %w", the returned error implements an Unwrap // method returning it. // // If the format specifier includes a %w verb with an error operand in a // position other than at the end, the returned error will still implement an // Unwrap method returning the operand, but the error's Format method will not // return the wrapped error. // // It is invalid to include more than one %w verb or to supply it with an // operand that does not implement the error interface. The %w verb is otherwise // a synonym for %v. func Errorf(format string, a ...interface{ … } func errorAt(args []interface{ … } // formatPlusW is used to avoid the vet check that will barf at %w. func formatPlusW(s string) string { … } // Return the index of the only %w in format, or -1 if none. // Also return a rewritten format string with %w replaced by %v, and // false if there is more than one %w. // TODO: handle "%[N]w". func parsePercentW(format string) (idx int, newFormat string, ok bool) { … } // Parse the printf verb starting with a % at s[0]. // Return how many bytes it occupies and whether the verb is 'w'. func parsePrintfVerb(s string) (int, bool) { … } type noWrapError … func (e *noWrapError) Error() string { … } func (e *noWrapError) Format(s fmt.State, v rune) { … } func (e *noWrapError) FormatError(p Printer) (next error) { … } type wrapError … func (e *wrapError) Error() string { … } func (e *wrapError) Format(s fmt.State, v rune) { … } func (e *wrapError) FormatError(p Printer) (next error) { … } func (e *wrapError) Unwrap() error { … }