-
Notifications
You must be signed in to change notification settings - Fork 77
/
main.go
48 lines (42 loc) · 1.03 KB
/
main.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
41
42
43
44
45
46
47
48
package main
import (
"os"
"runtime"
"strings"
"github.com/k0sproject/k0sctl/analytics"
"github.com/k0sproject/k0sctl/cmd"
log "github.com/sirupsen/logrus"
// blank import to make sure versioninfo is included in the binary
_ "github.com/carlmjohnson/versioninfo"
// blank import to make sure versioninfo is included in the binary
_ "github.com/k0sproject/k0sctl/version"
)
func handlepanic() {
if err := recover(); err != nil {
buf := make([]byte, 1<<16)
ss := runtime.Stack(buf, true)
msg := string(buf[:ss])
var bt []string
for _, row := range strings.Split(msg, "\n") {
if !strings.HasPrefix(row, "\t") {
continue
}
if strings.Contains(row, "main.") {
continue
}
if strings.Contains(row, "panic") {
continue
}
bt = append(bt, strings.TrimSpace(row))
}
analytics.Client.Publish("panic", map[string]interface{}{"backtrace": strings.Join(bt, "\n")})
log.Fatalf("PANIC: %v\n", err)
}
}
func main() {
defer handlepanic()
err := cmd.App.Run(os.Args)
if err != nil {
log.Fatal(err)
}
}