wrap adds a context message and stack trace to err and returns a new error containing the new context. This function is meant to be composed within other exported functions, such as Wrap and WithDetail. The argument stackSkip is the number of stack frames to ascend when generating stack straces, whe
(err error, msg string, stackSkip int)
| 41 | // The argument stackSkip is the number of stack frames to ascend when |
| 42 | // generating stack straces, where 0 is the caller of wrap. |
| 43 | func wrap(err error, msg string, stackSkip int) error { |
| 44 | if err == nil { |
| 45 | return nil |
| 46 | } |
| 47 | |
| 48 | werr, ok := err.(wrapperError) |
| 49 | if !ok { |
| 50 | werr.root = err |
| 51 | werr.msg = err.Error() |
| 52 | werr.stack = getStack(stackSkip+2, stackTraceSize) |
| 53 | } |
| 54 | if msg != "" { |
| 55 | werr.msg = msg + ": " + werr.msg |
| 56 | } |
| 57 | |
| 58 | return werr |
| 59 | } |
| 60 | |
| 61 | // Wrap adds a context message and stack trace to err and returns a new error |
| 62 | // with the new context. Arguments are handled as in fmt.Print. |
no test coverage detected