File tree 2 files changed +21
-11
lines changed
2 files changed +21
-11
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "fmt"
4
5
"os"
5
6
"runtime"
7
+ "runtime/debug"
6
8
7
9
"github.com/hashicorp/go-version"
8
10
"github.com/mattn/go-colorable"
28
30
GoArch = runtime .GOARCH
29
31
)
30
32
33
+ func cleanup (buildInfo * core.BuildInfo ) {
34
+ if err := recover (); err != nil {
35
+ fmt .Println (sentry .ErrorBanner )
36
+ fmt .Println ("stacktrace from panic: \n " + string (debug .Stack ()))
37
+
38
+ // This will send an anonymous report on Scaleway's sentry.
39
+ if buildInfo .IsRelease () {
40
+ sentry .RecoverPanicAndSendReport (buildInfo , err )
41
+ }
42
+ }
43
+ }
44
+
31
45
func main () {
32
46
buildInfo := & core.BuildInfo {
33
47
Version : version .Must (version .NewSemver (Version )), // panic when version does not respect semantic versionning
@@ -38,11 +52,7 @@ func main() {
38
52
GoOS : GoOS ,
39
53
GoArch : GoArch ,
40
54
}
41
-
42
- // Catch every panic after this line. This will send an anonymous report on Scaleway's sentry.
43
- if buildInfo .IsRelease () {
44
- defer sentry .RecoverPanicAndSendReport (buildInfo )
45
- }
55
+ defer cleanup (buildInfo )
46
56
47
57
exitCode , _ , _ := core .Bootstrap (& core.BootstrapConfig {
48
58
Args : os .Args ,
Original file line number Diff line number Diff line change @@ -12,14 +12,14 @@ const (
12
12
dsn = "https://[email protected] /186"
13
13
)
14
14
15
+ const ErrorBanner = `---------------------------------------------------------------------------------------
16
+ An error occurred, we are sorry, please consider opening a ticket on github using: 'scw feedback bug'
17
+ Give us as many details as possible so we can reproduce the error and fix it.
18
+ ---------------------------------------------------------------------------------------`
19
+
15
20
// RecoverPanicAndSendReport will recover error if any, log them, and send them to sentry.
16
21
// It must be called with the defer built-in.
17
- func RecoverPanicAndSendReport (buildInfo * core.BuildInfo ) {
18
- e := recover ()
19
- if e == nil {
20
- return
21
- }
22
-
22
+ func RecoverPanicAndSendReport (buildInfo * core.BuildInfo , e interface {}) {
23
23
sentryClient , err := newSentryClient (buildInfo )
24
24
if err != nil {
25
25
logger .Debugf ("cannot create sentry client: %s" , err )
You can’t perform that action at this time.
0 commit comments