Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better development ergonomics #294

Merged
merged 1 commit into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions internal/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func Execute() {
"no-input", false, "Disable interactivity.")

rootCmd.PersistentFlags().BoolVar(&cli.noColor,
"no-color", false, "Disable colors.")
"no-color", false, "Disable colors.")
// order of the comamnds here matters
// so add new commands in a place that reflect its relevance or relation with other commands:
rootCmd.AddCommand(loginCmd(cli))
Expand All @@ -111,7 +111,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 @@ -143,3 +151,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
}