14
14
// Adding context to an error
15
15
//
16
16
// The errors.Wrap function returns a new error that adds context to the
17
- // original error. For example
17
+ // original error by recording a stack trace at the point Wrap is called,
18
+ // and the supplied message. For example
18
19
//
19
20
// _, err := ioutil.ReadAll(r)
20
21
// if err != nil {
21
22
// return errors.Wrap(err, "read failed")
22
23
// }
23
24
//
25
+ // If additional control is required the errors.WithStack and errors.WithMessage
26
+ // functions destructure errors.Wrap into its component operations of annotating
27
+ // an error with a stack trace and an a message, respectively.
28
+ //
24
29
// Retrieving the cause of an error
25
30
//
26
31
// Using errors.Wrap constructs a stack of errors, adding context to the
@@ -169,7 +174,8 @@ func (w *withStack) Format(s fmt.State, verb rune) {
169
174
}
170
175
}
171
176
172
- // Wrap returns an error annotating err with message.
177
+ // Wrap returns an error annotating err with a stack trace
178
+ // at the point Wrap is called, and the supplied message.
173
179
// If err is nil, Wrap returns nil.
174
180
func Wrap (err error , message string ) error {
175
181
if err == nil {
@@ -185,7 +191,8 @@ func Wrap(err error, message string) error {
185
191
}
186
192
}
187
193
188
- // Wrapf returns an error annotating err with the format specifier.
194
+ // Wrapf returns an error annotating err with a stack trace
195
+ // at the point Wrapf is call, and the format specifier.
189
196
// If err is nil, Wrapf returns nil.
190
197
func Wrapf (err error , format string , args ... interface {}) error {
191
198
if err == nil {
0 commit comments