-
Notifications
You must be signed in to change notification settings - Fork 69
/
panicwrap.go
32 lines (26 loc) · 949 Bytes
/
panicwrap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package bugsnag
import (
"github.com/bugsnag/bugsnag-go/errors"
"github.com/bugsnag/bugsnag-go/sessions"
"github.com/bugsnag/panicwrap"
)
// Forks and re-runs your program to add panic monitoring. This function does
// not return on one process, instead listening on stderr of the other process,
// which returns nil.
//
// Related: https://godoc.org/github.com/bugsnag/panicwrap#BasicMonitor
func defaultPanicHandler() {
defer defaultNotifier.dontPanic()
ctx := sessions.SendStartupSession(&sessionTrackingConfig)
err := panicwrap.BasicMonitor(func(output string) {
toNotify, err := errors.ParsePanic(output)
if err != nil {
defaultNotifier.Config.logf("bugsnag.handleUncaughtPanic: %v", err)
}
state := HandledState{SeverityReasonUnhandledPanic, SeverityError, true, ""}
defaultNotifier.NotifySync(toNotify, true, state, ctx)
})
if err != nil {
defaultNotifier.Config.logf("bugsnag.handleUncaughtPanic: %v", err)
}
}