forked from bugsnag/bugsnag-go
/
panicwrap.go
40 lines (32 loc) · 868 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
33
34
35
36
37
38
39
40
// +build !appengine
package bugsnag
import (
"github.com/kyrylo/bugsnag-go/errors"
"github.com/mitchellh/panicwrap"
"os"
)
// NOTE: this function does not return when you call it, instead it
// re-exec()s the current process with panic monitoring.
func defaultPanicHandler() {
defer defaultNotifier.dontPanic()
exitStatus, err := panicwrap.Wrap(&panicwrap.WrapConfig{
CookieKey: "bugsnag_wrapped",
CookieValue: "bugsnag_wrapped",
Handler: func(output string) {
toNotify, err := errors.ParsePanic(output)
if err != nil {
defaultNotifier.Config.log("bugsnag.handleUncaughtPanic: %v", err)
}
Notify(toNotify, SeverityError, Configuration{Synchronous: true})
},
})
if err != nil {
defaultNotifier.Config.log("bugsnag.handleUncaughtPanic: %v", err)
return
}
if exitStatus >= 0 {
os.Exit(exitStatus)
} else {
return
}
}