Wrap makes an Error from the given value. If that value is already an error then it will be used directly, if not, it will be passed to fmt.Errorf("%v"). The skip parameter indicates how far up the stack to start the stacktrace. 0 is from the current call, 1 from its caller, etc.
(e interface{}, skip int)
| 91 | // fmt.Errorf("%v"). The skip parameter indicates how far up the stack |
| 92 | // to start the stacktrace. 0 is from the current call, 1 from its caller, etc. |
| 93 | func Wrap(e interface{}, skip int) *Error { |
| 94 | if e == nil { |
| 95 | return nil |
| 96 | } |
| 97 | |
| 98 | var err error |
| 99 | |
| 100 | switch e := e.(type) { |
| 101 | case *Error: |
| 102 | return e |
| 103 | case error: |
| 104 | err = e |
| 105 | default: |
| 106 | err = fmt.Errorf("%v", e) |
| 107 | } |
| 108 | |
| 109 | stack := make([]uintptr, MaxStackDepth) |
| 110 | length := runtime.Callers(2+skip, stack[:]) |
| 111 | return &Error{ |
| 112 | Err: err, |
| 113 | stack: stack[:length], |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | // WrapPrefix makes an Error from the given value. If that value is already an |
| 118 | // error then it will be used directly, if not, it will be passed to |
searching dependent graphs…