| 1 | // Copyright 2018 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package fmt |
| 6 | |
| 7 | import "golang.org/x/exp/errors" |
| 8 | |
| 9 | // The functionality in this file is to provide adaptors only. It will not |
| 10 | // be included in the standard library. |
| 11 | |
| 12 | // FormatError calls the FormatError method of err with a errors.Printer |
| 13 | // configured according to s and verb and writes the result to s. |
| 14 | func FormatError(s State, verb rune, err errors.Formatter) { |
| 15 | // Assuming this function is only called from the Format method, and given |
| 16 | // that FormatError takes precedence over Format, it cannot be called from |
| 17 | // any package that supports errors.Formatter. It is therefore safe to |
| 18 | // disregard that State may be a specific printer implementation and use one |
| 19 | // of our choice instead. |
| 20 | p := newPrinter() |
| 21 | if verb == 'v' { |
| 22 | if s.Flag('#') { |
| 23 | p.fmt.sharpV = true |
| 24 | } |
| 25 | if s.Flag('+') { |
| 26 | p.fmt.plusV = true |
| 27 | } |
| 28 | } |
| 29 | fmtError(p, verb, err) |
| 30 | s.Write(p.buf) |
| 31 | } |