From db4fd08a92e4433c5d17280e6f0e4cce82cd93f9 Mon Sep 17 00:00:00 2001 From: morganelle Date: Tue, 2 Mar 2021 15:10:49 -0800 Subject: [PATCH 1/3] update error messages for tenants command --- internal/cli/tenants.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/internal/cli/tenants.go b/internal/cli/tenants.go index 843a6a2ec..12344f3ff 100644 --- a/internal/cli/tenants.go +++ b/internal/cli/tenants.go @@ -32,7 +32,7 @@ func useTenantCmd(cli *cli) *cobra.Command { if len(args) == 0 { tens, err := cli.listTenants() if err != nil { - return fmt.Errorf("unable to load tenants from config") + return fmt.Errorf("Unable to load tenants due to an unexpected error: %w", err) } tenNames := make([]string, len(tens)) @@ -42,21 +42,20 @@ func useTenantCmd(cli *cli) *cobra.Command { input := prompt.SelectInput("tenant", "Tenant:", "Tenant to activate", tenNames, true) if err := prompt.AskOne(input, &selectedTenant); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } else { requestedTenant := args[0] t, ok := cli.config.Tenants[requestedTenant] if !ok { - return fmt.Errorf("Unable to find tenant in config: %s", requestedTenant) - + return fmt.Errorf("Unable to find tenant %s; run `auth0 tenants use` to see your configured tenants or run `auth0 login` to configure a new tenant", requestedTenant) } selectedTenant = t.Name } cli.config.DefaultTenant = selectedTenant if err := cli.persistConfig(); err != nil { - return fmt.Errorf("persisting config: %w", err) + return fmt.Errorf("An error occurred while setting the default tenant: %w", err) } return nil }, From a8fbf79498125ba0e5eb230b2288cdc1260abc1d Mon Sep 17 00:00:00 2001 From: morganelle Date: Tue, 2 Mar 2021 15:33:25 -0800 Subject: [PATCH 2/3] updated error messages for apis command --- internal/cli/apis.go | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 257ce4211..90f0ab2ff 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -2,6 +2,7 @@ package cli import ( "errors" + "fmt" "strings" "github.com/auth0/auth0-cli/internal/ansi" @@ -66,7 +67,7 @@ Lists your existing APIs. To create one try: }) if err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } cli.renderer.ApiList(list.ResourceServers) @@ -99,10 +100,10 @@ auth0 apis show input := prompt.TextInput(apiID, "Id:", "Id of the API.", true) if err := prompt.AskOne(input, &inputs); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } else { - return errors.New("missing API id") + return errors.New("Please include an API id") } } else { inputs.ID = args[0] @@ -117,7 +118,7 @@ auth0 apis show }) if err != nil { - return err + return fmt.Errorf("Unable to find an API with id %s: %w", inputs.ID, err) } cli.renderer.ApiShow(api) @@ -153,7 +154,7 @@ auth0 apis create --name myapi --identifier http://my-api true) if err := prompt.AskOne(input, &flags); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } @@ -164,7 +165,7 @@ auth0 apis create --name myapi --identifier http://my-api true) if err := prompt.AskOne(input, &flags); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } @@ -172,7 +173,7 @@ auth0 apis create --name myapi --identifier http://my-api input := prompt.TextInput(apiScopes, "Scopes:", "Space-separated list of scopes.", false) if err := prompt.AskOne(input, &flags); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } @@ -190,7 +191,7 @@ auth0 apis create --name myapi --identifier http://my-api }) if err != nil { - return err + return fmt.Errorf("An unexpected error occurred while attempting to create an API with name %s and identifier %s : %w", flags.Name, flags.Identifier, err) } cli.renderer.ApiCreate(api) @@ -230,10 +231,10 @@ auth0 apis update --name myapi input := prompt.TextInput(apiID, "Id:", "Id of the API.", true) if err := prompt.AskOne(input, &inputs); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } else { - return errors.New("missing API id") + return errors.New("Please include an API id") } } else { inputs.ID = args[0] @@ -243,7 +244,7 @@ auth0 apis update --name myapi input := prompt.TextInput(apiName, "Name:", "Name of the API.", true) if err := prompt.AskOne(input, &inputs); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } @@ -251,7 +252,7 @@ auth0 apis update --name myapi input := prompt.TextInput(apiScopes, "Scopes:", "Space-separated list of scopes.", false) if err := prompt.AskOne(input, &inputs); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } @@ -266,7 +267,7 @@ auth0 apis update --name myapi }) if err != nil { - return err + return fmt.Errorf("An unexpected error occurred while updating the API with id %s: %w", inputs.ID, err) } cli.renderer.ApiUpdate(api) @@ -302,10 +303,10 @@ auth0 apis delete input := prompt.TextInput(apiID, "Id:", "Id of the API.", true) if err := prompt.AskOne(input, &inputs); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } else { - return errors.New("missing API id") + return errors.New("Please include an API id") } } else { inputs.ID = args[0] @@ -318,7 +319,11 @@ auth0 apis delete } return ansi.Spinner("Deleting API", func() error { - return cli.api.ResourceServer.Delete(inputs.ID) + err := cli.api.ResourceServer.Delete(inputs.ID) + if err != nil { + return fmt.Errorf("An unexpected error occurred while attempting to delete an API with id %s: %w", inputs.ID, err) + } + return nil }) }, } @@ -348,10 +353,10 @@ auth0 apis scopes list input := prompt.TextInput(apiID, "Id:", "Id of the API.", true) if err := prompt.AskOne(input, &inputs); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %w", err) } } else { - return errors.New("missing API id") + return errors.New("Please include an API id") } } else { inputs.ID = args[0] @@ -366,7 +371,7 @@ auth0 apis scopes list }) if err != nil { - return err + return fmt.Errorf("An unexpected error occurred while getting scopes for the API with id %s: %w", inputs.ID, err) } cli.renderer.ScopesList(api.GetName(), api.Scopes) From f7fdc9a10a0fd7de1c6128237b5125590ee76a0f Mon Sep 17 00:00:00 2001 From: morganelle Date: Tue, 2 Mar 2021 15:39:39 -0800 Subject: [PATCH 3/3] small tweaks to apis error language --- internal/cli/apis.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/cli/apis.go b/internal/cli/apis.go index 90f0ab2ff..e8707252c 100644 --- a/internal/cli/apis.go +++ b/internal/cli/apis.go @@ -118,7 +118,7 @@ auth0 apis show }) if err != nil { - return fmt.Errorf("Unable to find an API with id %s: %w", inputs.ID, err) + return fmt.Errorf("Unable to get an API with id %s: %w", inputs.ID, err) } cli.renderer.ApiShow(api) @@ -267,7 +267,7 @@ auth0 apis update --name myapi }) if err != nil { - return fmt.Errorf("An unexpected error occurred while updating the API with id %s: %w", inputs.ID, err) + return fmt.Errorf("An unexpected error occurred while trying to update an API with id %s: %w", inputs.ID, err) } cli.renderer.ApiUpdate(api) @@ -371,7 +371,7 @@ auth0 apis scopes list }) if err != nil { - return fmt.Errorf("An unexpected error occurred while getting scopes for the API with id %s: %w", inputs.ID, err) + return fmt.Errorf("An unexpected error occurred while getting scopes for an API with id %s: %w", inputs.ID, err) } cli.renderer.ScopesList(api.GetName(), api.Scopes)