|
13 | 13 | // |
14 | 14 | // Adding context to an error |
15 | 15 | // |
16 | | -// The errors.Wrap function returns a new error that adds context to the |
17 | | -// original error by recording a stack trace at the point Wrap is called, |
| 16 | +// The errors.Annotate function returns a new error that adds context to the |
| 17 | +// original error by recording a stack trace at the point Annotate is called, |
18 | 18 | // and the supplied message. For example |
19 | 19 | // |
20 | 20 | // _, err := ioutil.ReadAll(r) |
21 | 21 | // if err != nil { |
22 | | -// return errors.Wrap(err, "read failed") |
| 22 | +// return errors.Annotate(err, "read failed") |
23 | 23 | // } |
24 | 24 | // |
25 | | -// If additional control is required the errors.WithStack and errors.WithMessage |
26 | | -// functions destructure errors.Wrap into its component operations of annotating |
| 25 | +// If additional control is required the errors.AddStack and errors.WithMessage |
| 26 | +// functions destructure errors.Annotate into its component operations of annotating |
27 | 27 | // an error with a stack trace and an a message, respectively. |
28 | 28 | // |
29 | 29 | // Retrieving the cause of an error |
30 | 30 | // |
31 | | -// Using errors.Wrap constructs a stack of errors, adding context to the |
| 31 | +// Using errors.Annotate constructs a stack of errors, adding context to the |
32 | 32 | // preceding error. Depending on the nature of the error it may be necessary |
33 | | -// to reverse the operation of errors.Wrap to retrieve the original error |
| 33 | +// to reverse the operation of errors.Annotate to retrieve the original error |
34 | 34 | // for inspection. Any error value which implements this interface |
35 | 35 | // |
36 | 36 | // type causer interface { |
|
50 | 50 | // |
51 | 51 | // causer interface is not exported by this package, but is considered a part |
52 | 52 | // of stable public API. |
| 53 | +// errors.Unwrap is also available: this will retrieve the next error in the chain. |
53 | 54 | // |
54 | 55 | // Formatted printing of errors |
55 | 56 | // |
|
64 | 65 | // |
65 | 66 | // Retrieving the stack trace of an error or wrapper |
66 | 67 | // |
67 | | -// New, Errorf, Wrap, and Wrapf record a stack trace at the point they are invoked. |
| 68 | +// New, Errorf, Annotate, and Annotatef record a stack trace at the point they are invoked. |
68 | 69 | // This information can be retrieved with the StackTracer interface that returns |
69 | 70 | // a StackTrace. Where errors.StackTrace is defined as |
70 | 71 | // |
|
81 | 82 | // } |
82 | 83 | // |
83 | 84 | // See the documentation for Frame.Format for more details. |
| 85 | +// |
| 86 | +// errors.Find can be used to search for an error in the error chain. |
84 | 87 | package errors |
85 | 88 |
|
86 | 89 | import ( |
@@ -148,6 +151,8 @@ func (f *fundamental) Format(s fmt.State, verb rune) { |
148 | 151 |
|
149 | 152 | // WithStack annotates err with a stack trace at the point WithStack was called. |
150 | 153 | // If err is nil, WithStack returns nil. |
| 154 | +// |
| 155 | +// Deprecated: use AddStack |
151 | 156 | func WithStack(err error) error { |
152 | 157 | if err == nil { |
153 | 158 | return nil |
@@ -317,7 +322,8 @@ func Unwrap(err error) error { |
317 | 322 | return nil |
318 | 323 | } |
319 | 324 |
|
320 | | -// Find an error in the chain that matches a test function |
| 325 | +// Find an error in the chain that matches a test function. |
| 326 | +// returns nil if no error is found. |
321 | 327 | func Find(origErr error, test func(error) bool) error { |
322 | 328 | var foundErr error |
323 | 329 | WalkDeep(origErr, func(err error) bool { |
|
0 commit comments