func FormatError(f Formatter, s fmt.State, verb rune) {
	var (
		sep    = " "  
		p      = &state{State: s}
		direct = true
	)
	var err error = f
	switch verb {
	case 'v':
		if s.Flag('#') {
			if stringer, ok := err.(fmt.GoStringer); ok {
				io.WriteString(&p.buf, stringer.GoString())
				goto exit
			}
		} else if s.Flag('+') {
			p.printDetail = true
			sep = "\n  - "
		}
	case 's':
	case 'q', 'x', 'X':
		direct = false
	default:
		p.buf.WriteString("%!")
		p.buf.WriteRune(verb)
		p.buf.WriteByte('(')
		switch {
		case err != nil:
			p.buf.WriteString(reflect.TypeOf(f).String())
		default:
			p.buf.WriteString("<nil>")
		}
		p.buf.WriteByte(')')
		io.Copy(s, &p.buf)
		return
	}
loop:
	for {
		switch v := err.(type) {
		case Formatter:
			err = v.FormatError((*printer)(p))
		case fmt.Formatter:
			v.Format(p, 'v')
			break loop
		default:
			io.WriteString(&p.buf, v.Error())
			break loop
		}
		if err == nil {
			break
		}
		if p.needColon || !p.printDetail {
			p.buf.WriteByte(':')
			p.needColon = false
		}
		p.buf.WriteString(sep)
		p.inDetail = false
		p.needNewline = false
	}
exit:
	width, okW := s.Width()
	prec, okP := s.Precision()
	if !direct || (okW && width > 0) || okP {
		format := []byte{'%'}
		if s.Flag('-') {
			format = append(format, '-')
		}
		if s.Flag('+') {
			format = append(format, '+')
		}
		if s.Flag(' ') {
			format = append(format, ' ')
		}
		if okW {
			format = strconv.AppendInt(format, int64(width), 10)
		}
		if okP {
			format = append(format, '.')
			format = strconv.AppendInt(format, int64(prec), 10)
		}
		format = append(format, string(verb)...)
		fmt.Fprintf(s, string(format), p.buf.String())
	} else {
		io.Copy(s, &p.buf)
	}
}
FormatError calls the FormatError method of f with an errors.Printer
configured according to s and verb, and writes the result to s.
package xerrors
import (
	"bytes"
	"fmt"
	"io"
	"reflect"
	"strconv"
)