...
Source file
src/fmt/errors.go
Documentation: fmt
1
2
3
4
5 package fmt
6
7 import "errors"
8
9
10
11
12
13
14
15
16
17 func Errorf(format string, a ...interface{}) error {
18 p := newPrinter()
19 p.wrapErrs = true
20 p.doPrintf(format, a)
21 s := string(p.buf)
22 var err error
23 if p.wrappedErr == nil {
24 err = errors.New(s)
25 } else {
26 err = &wrapError{s, p.wrappedErr}
27 }
28 p.free()
29 return err
30 }
31
32 type wrapError struct {
33 msg string
34 err error
35 }
36
37 func (e *wrapError) Error() string {
38 return e.msg
39 }
40
41 func (e *wrapError) Unwrap() error {
42 return e.err
43 }
44
View as plain text