Annotatef is used to add extra context to an existing error. The location of the Annotate call is recorded with the annotations. The file, line and function are also recorded. For example: if err := SomeFunc(); err != nil { return errors.Annotatef(err, "failed to frombulate the %s", arg) }
(other error, format string, args ...interface{})
| 97 | // } |
| 98 | // |
| 99 | func Annotatef(other error, format string, args ...interface{}) error { |
| 100 | if other == nil { |
| 101 | return nil |
| 102 | } |
| 103 | err := &Err{ |
| 104 | previous: other, |
| 105 | cause: Cause(other), |
| 106 | message: fmt.Sprintf(format, args...), |
| 107 | } |
| 108 | err.SetLocation(1) |
| 109 | return err |
| 110 | } |
| 111 | |
| 112 | // DeferredAnnotatef annotates the given error (when it is not nil) with the given |
| 113 | // format string and arguments (like fmt.Sprintf). If *err is nil, DeferredAnnotatef |
searching dependent graphs…