RecoverAndLogError must be used inside a defer.
(ctx context.Context)
| 233 | |
| 234 | // RecoverAndLogError must be used inside a defer. |
| 235 | func RecoverAndLogError(ctx context.Context) { |
| 236 | Helper() |
| 237 | if err := recover(); err != nil { |
| 238 | const size = 64 << 10 |
| 239 | buf := make([]byte, size) |
| 240 | buf = buf[:runtime.Stack(buf, false)] |
| 241 | Printkv(ctx, |
| 242 | KeyMessage, "panic", |
| 243 | KeyError, err, |
| 244 | KeyStack, buf, |
| 245 | ) |
| 246 | } |
| 247 | } |