From 44f54418252460934848895b6344027c9654a5d9 Mon Sep 17 00:00:00 2001 From: Rita Zerrizuela Date: Fri, 7 May 2021 22:32:43 -0300 Subject: [PATCH] Add auth0.Error --- go.mod | 1 + internal/ansi/spinner.go | 3 ++- internal/auth0/error.go | 7 +++++++ internal/cli/flags.go | 9 +++++---- internal/cli/quickstarts.go | 2 +- vendor/modules.txt | 1 + 6 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 internal/auth0/error.go diff --git a/go.mod b/go.mod index eba6991e5..935cc5e7c 100644 --- a/go.mod +++ b/go.mod @@ -26,6 +26,7 @@ require ( github.com/mholt/archiver/v3 v3.5.0 github.com/olekukonko/tablewriter v0.0.5 github.com/pierrec/lz4/v4 v4.1.3 // indirect + github.com/pkg/errors v0.9.1 github.com/rivo/uniseg v0.2.0 // indirect github.com/spf13/cobra v1.1.3 github.com/spf13/pflag v1.0.5 diff --git a/internal/ansi/spinner.go b/internal/ansi/spinner.go index 302ba8da9..52a70703b 100644 --- a/internal/ansi/spinner.go +++ b/internal/ansi/spinner.go @@ -4,6 +4,7 @@ import ( "os" "time" + "github.com/auth0/auth0-cli/internal/auth0" "github.com/briandowns/spinner" ) @@ -40,7 +41,7 @@ func loading(initialMsg, doneMsg, failMsg string, fn func() error) error { s.Writer = os.Stderr if err := s.Color(spinnerColor); err != nil { - panic(err) + panic(auth0.Error(err, "failed setting spinner color")) } s.Start() diff --git a/internal/auth0/error.go b/internal/auth0/error.go new file mode 100644 index 000000000..7b79eec13 --- /dev/null +++ b/internal/auth0/error.go @@ -0,0 +1,7 @@ +package auth0 + +import "github.com/pkg/errors" + +func Error(e error, message string) error { + return errors.Wrap(e, message) +} diff --git a/internal/cli/flags.go b/internal/cli/flags.go index cef467ebd..6b4a2e53b 100644 --- a/internal/cli/flags.go +++ b/internal/cli/flags.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/AlecAivazis/survey/v2" + "github.com/auth0/auth0-cli/internal/auth0" "github.com/auth0/auth0-cli/internal/prompt" "github.com/spf13/cobra" ) @@ -209,7 +210,7 @@ func registerString(cmd *cobra.Command, f *Flag, value *string, defaultValue str cmd.Flags().StringVarP(value, f.LongForm, f.ShortForm, defaultValue, f.Help) if err := markFlagRequired(cmd, f, isUpdate); err != nil { - panic(unexpectedError(err)) // TODO: Handle + panic(auth0.Error(err, "failed to register string flag")) } } @@ -217,7 +218,7 @@ func registerStringSlice(cmd *cobra.Command, f *Flag, value *[]string, defaultVa cmd.Flags().StringSliceVarP(value, f.LongForm, f.ShortForm, defaultValue, f.Help) if err := markFlagRequired(cmd, f, isUpdate); err != nil { - panic(unexpectedError(err)) // TODO: Handle + panic(auth0.Error(err, "failed to register string slice flag")) } } @@ -225,7 +226,7 @@ func registerInt(cmd *cobra.Command, f *Flag, value *int, defaultValue int, isUp cmd.Flags().IntVarP(value, f.LongForm, f.ShortForm, defaultValue, f.Help) if err := markFlagRequired(cmd, f, isUpdate); err != nil { - panic(unexpectedError(err)) // TODO: Handle + panic(auth0.Error(err, "failed to register int flag")) } } @@ -233,7 +234,7 @@ func registerBool(cmd *cobra.Command, f *Flag, value *bool, defaultValue bool, i cmd.Flags().BoolVarP(value, f.LongForm, f.ShortForm, defaultValue, f.Help) if err := markFlagRequired(cmd, f, isUpdate); err != nil { - panic(unexpectedError(err)) // TODO: Handle + panic(auth0.Error(err, "failed to register bool flag")) } } diff --git a/internal/cli/quickstarts.go b/internal/cli/quickstarts.go index 605dbf00d..d307bed75 100644 --- a/internal/cli/quickstarts.go +++ b/internal/cli/quickstarts.go @@ -46,7 +46,7 @@ var ( qsBuf []byte quickstartsByType = func() (qs map[string][]auth0.Quickstart) { if err := json.Unmarshal(qsBuf, &qs); err != nil { - panic(err) + panic(auth0.Error(err, "failed to unmarshal data/quickstarts.json")) } return }() diff --git a/vendor/modules.txt b/vendor/modules.txt index 746ce06ec..42144ae8a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -205,6 +205,7 @@ github.com/pierrec/lz4/v4/internal/lz4errors github.com/pierrec/lz4/v4/internal/lz4stream github.com/pierrec/lz4/v4/internal/xxh32 # github.com/pkg/errors v0.9.1 +## explicit github.com/pkg/errors # github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib/difflib