HandleCrash simply catches a crash and logs an error. Meant to be called via defer. Additional context-specific handlers can be provided, and will be called in case of panic. HandleCrash actually crashes, after calling the handlers and logging the panic message. TODO: remove this function. We are
(additionalHandlers ...func(interface{}))
| 46 | // catching panics was important. But it's actually much simpler for montoring |
| 47 | // software if we just exit when an unexpected panic happens. |
| 48 | func HandleCrash(additionalHandlers ...func(interface{})) { |
| 49 | if r := recover(); r != nil { |
| 50 | for _, fn := range PanicHandlers { |
| 51 | fn(r) |
| 52 | } |
| 53 | for _, fn := range additionalHandlers { |
| 54 | fn(r) |
| 55 | } |
| 56 | if ReallyCrash { |
| 57 | // Actually proceed to panic. |
| 58 | panic(r) |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | // logPanic logs the caller tree when a panic occurs. |
| 64 | func logPanic(r interface{}) { |
no outgoing calls