Skip to content

Commit

Permalink
Merge branch 'main' into feat-add-roles
Browse files Browse the repository at this point in the history
  • Loading branch information
Widcket authored May 15, 2021
2 parents e3b82d1 + 7d7b32e commit d2e88d8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
17 changes: 16 additions & 1 deletion internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,15 @@ func Execute() {
defer func() {
if v := recover(); v != nil {
err := fmt.Errorf("panic: %v", v)
instrumentation.ReportException(err)

// If we're in development mode, we should throw the
// panic for so we have less surprises. For
// non-developers, we'll swallow the panics.
if instrumentation.ReportException(err) {
fmt.Println(panicMessage)
} else {
panic(v)
}
}
}()

Expand Down Expand Up @@ -144,3 +152,10 @@ func contextWithSignal(sigs ...os.Signal) context.Context {

return ctx
}

const panicMessage = `
!! Uh oh. Something went wrong.
!! If this problem keeps happening feel free to report an issue at
!!
!! https://github.com/auth0/auth0-cli/issues/new/choose
`
7 changes: 4 additions & 3 deletions internal/instrumentation/instrumentation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@ var SentryDSN string

// ReportException is designed to be called once as the CLI exits. We're
// purposefully initializing a client all the time given this context.
func ReportException(err error) {
func ReportException(err error) bool {
if SentryDSN == "" {
return
return false
}

if err := sentry.Init(sentry.ClientOptions{Dsn: SentryDSN}); err != nil {
return
return false
}

// Flush buffered events before the program terminates.
sentry.CaptureException(err)

// Allow up to 2s to flush, otherwise quit.
sentry.Flush(2 * time.Second)
return true
}

0 comments on commit d2e88d8

Please sign in to comment.