StackError adds one more line of message to err. It updates err if it's already a StackedError, otherwise creates a new StackedError with the message from err and the stack trace of current goroutine.
(err error, message string, args ...interface{})
| 56 | // It updates err if it's already a StackedError, otherwise creates a new StackedError |
| 57 | // with the message from err and the stack trace of current goroutine. |
| 58 | func StackError(err error, message string, args ...interface{}) *StackedError { |
| 59 | if err == nil { |
| 60 | stack := make([]byte, 0x10000) |
| 61 | runtime.Stack(stack, false) |
| 62 | e := &StackedError{ |
| 63 | []string{fmt.Sprintf(message, args...)}, |
| 64 | strings.Split(string(stack), "\n"), |
| 65 | } |
| 66 | e.Stack = e.Stack[:len(e.Stack)-1] |
| 67 | return e |
| 68 | } |
| 69 | |
| 70 | e, ok := err.(*StackedError) |
| 71 | if !ok { |
| 72 | stack := make([]byte, 0x10000) |
| 73 | runtime.Stack(stack, false) |
| 74 | e = &StackedError{ |
| 75 | []string{err.Error()}, |
| 76 | strings.Split(string(stack), "\n"), |
| 77 | } |
| 78 | e.Stack = e.Stack[:len(e.Stack)-1] |
| 79 | } |
| 80 | |
| 81 | if message != "" { |
| 82 | e.Messages = append(e.Messages, fmt.Sprintf(message, args...)) |
| 83 | } |
| 84 | return e |
| 85 | } |
| 86 | |
| 87 | // RecoverWrap recover all panics inside the passed in func |
| 88 | func RecoverWrap(call func() error) (err error) { |
no test coverage detected