From 719698d389ba76dda30966f49fb6f656352f3e44 Mon Sep 17 00:00:00 2001 From: morganelle Date: Fri, 26 Feb 2021 14:12:20 -0800 Subject: [PATCH 1/4] customize error messages for test command --- internal/cli/test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/cli/test.go b/internal/cli/test.go index 53d8e425d..f3afd067a 100644 --- a/internal/cli/test.go +++ b/internal/cli/test.go @@ -46,14 +46,14 @@ Launch a browser to try out your universal login box for the given client. if clientID == "" { client, err := getOrCreateCLITesterClient(cli.api.Client) if err != nil { - return err + return fmt.Errorf("Unable to test the login box; please check your internet connection and verify you haven't reached your apps limit") } clientID = client.GetClientID() } client, err := cli.api.Client.Read(clientID) if err != nil { - return err + return fmt.Errorf("Unable to find client %s; if you specified a client, please verify it exists, otherwise re-run the command", clientID) } if proceed := runLoginFlowPreflightChecks(cli, client); !proceed { @@ -70,7 +70,7 @@ Launch a browser to try out your universal login box for the given client. cliLoginTestingScopes, ) if err != nil { - return err + return fmt.Errorf("An unexpected error occurred while logging in to client %s: %e", clientID, err) } if err := ansi.Spinner("Fetching user metadata", func() error { @@ -79,7 +79,7 @@ Launch a browser to try out your universal login box for the given client. userInfo, err = authutil.FetchUserInfo(tenant.Domain, tokenResponse.AccessToken) return err }); err != nil { - return err + return fmt.Errorf("An unexpected error occurred: %e", err) } fmt.Fprint(cli.renderer.MessageWriter, "\n") @@ -118,14 +118,14 @@ Fetch an access token for the given client and API. if clientID == "" { client, err := getOrCreateCLITesterClient(cli.api.Client) if err != nil { - return err + return fmt.Errorf("Unable to fetch a token; please check your internet connection and verify you haven't reached your apps limit") } clientID = client.GetClientID() } client, err := cli.api.Client.Read(clientID) if err != nil { - return err + return fmt.Errorf("Unable to find client %s; if you specified a client, please verify it exists, otherwise re-run the command", clientID) } appType := client.GetAppType() @@ -140,7 +140,7 @@ Fetch an access token for the given client and API. if appType == "non_interactive" { tokenResponse, err := runClientCredentialsFlow(cli, client, clientID, audience, tenant) if err != nil { - return err + return fmt.Errorf("An unexpected error occurred while logging in to machine-to-machine client %s: %e", clientID, err) } fmt.Fprint(cli.renderer.MessageWriter, "\n") @@ -162,7 +162,7 @@ Fetch an access token for the given client and API. scopes, ) if err != nil { - return err + return fmt.Errorf("An unexpected error occurred when logging in to client %s: %e", clientID, err) } fmt.Fprint(cli.renderer.MessageWriter, "\n") From 939a53305972025d8f3134ae81792558e859f088 Mon Sep 17 00:00:00 2001 From: morganelle Date: Fri, 26 Feb 2021 14:25:46 -0800 Subject: [PATCH 2/4] fix error verb --- internal/cli/test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/cli/test.go b/internal/cli/test.go index f3afd067a..7d3e75f78 100644 --- a/internal/cli/test.go +++ b/internal/cli/test.go @@ -70,7 +70,7 @@ Launch a browser to try out your universal login box for the given client. cliLoginTestingScopes, ) if err != nil { - return fmt.Errorf("An unexpected error occurred while logging in to client %s: %e", clientID, err) + return fmt.Errorf("An unexpected error occurred while logging in to client %s: %w", clientID, err) } if err := ansi.Spinner("Fetching user metadata", func() error { @@ -79,7 +79,7 @@ Launch a browser to try out your universal login box for the given client. userInfo, err = authutil.FetchUserInfo(tenant.Domain, tokenResponse.AccessToken) return err }); err != nil { - return fmt.Errorf("An unexpected error occurred: %e", err) + return fmt.Errorf("An unexpected error occurred: %w", err) } fmt.Fprint(cli.renderer.MessageWriter, "\n") @@ -140,7 +140,7 @@ Fetch an access token for the given client and API. if appType == "non_interactive" { tokenResponse, err := runClientCredentialsFlow(cli, client, clientID, audience, tenant) if err != nil { - return fmt.Errorf("An unexpected error occurred while logging in to machine-to-machine client %s: %e", clientID, err) + return fmt.Errorf("An unexpected error occurred while logging in to machine-to-machine client %s: %w", clientID, err) } fmt.Fprint(cli.renderer.MessageWriter, "\n") @@ -162,7 +162,7 @@ Fetch an access token for the given client and API. scopes, ) if err != nil { - return fmt.Errorf("An unexpected error occurred when logging in to client %s: %e", clientID, err) + return fmt.Errorf("An unexpected error occurred when logging in to client %s: %w", clientID, err) } fmt.Fprint(cli.renderer.MessageWriter, "\n") From 3e3dd49203ee5400b969d71cdb5e9b7c7440f5b0 Mon Sep 17 00:00:00 2001 From: morganelle Date: Fri, 26 Feb 2021 14:42:46 -0800 Subject: [PATCH 3/4] replace error format with new error when appropriate --- internal/cli/test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/internal/cli/test.go b/internal/cli/test.go index 7d3e75f78..c78708e47 100644 --- a/internal/cli/test.go +++ b/internal/cli/test.go @@ -1,6 +1,7 @@ package cli import ( + "errors" "fmt" "github.com/auth0/auth0-cli/internal/ansi" @@ -46,7 +47,7 @@ Launch a browser to try out your universal login box for the given client. if clientID == "" { client, err := getOrCreateCLITesterClient(cli.api.Client) if err != nil { - return fmt.Errorf("Unable to test the login box; please check your internet connection and verify you haven't reached your apps limit") + return errors.New("Unable to test the login box; please check your internet connection and verify you haven't reached your apps limit") } clientID = client.GetClientID() } @@ -118,7 +119,7 @@ Fetch an access token for the given client and API. if clientID == "" { client, err := getOrCreateCLITesterClient(cli.api.Client) if err != nil { - return fmt.Errorf("Unable to fetch a token; please check your internet connection and verify you haven't reached your apps limit") + return errors.New("Unable to fetch a token; please check your internet connection and verify you haven't reached your apps limit") } clientID = client.GetClientID() } From 1053757907b9ed6ba637e1b9d5d2f43b9aab2e37 Mon Sep 17 00:00:00 2001 From: morganelle Date: Fri, 26 Feb 2021 15:19:32 -0800 Subject: [PATCH 4/4] updated test command errors for getOrCreateCLITesterClient --- internal/cli/test.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/internal/cli/test.go b/internal/cli/test.go index c78708e47..d2707ee5a 100644 --- a/internal/cli/test.go +++ b/internal/cli/test.go @@ -1,7 +1,6 @@ package cli import ( - "errors" "fmt" "github.com/auth0/auth0-cli/internal/ansi" @@ -47,7 +46,7 @@ Launch a browser to try out your universal login box for the given client. if clientID == "" { client, err := getOrCreateCLITesterClient(cli.api.Client) if err != nil { - return errors.New("Unable to test the login box; please check your internet connection and verify you haven't reached your apps limit") + return fmt.Errorf("Unable to create an app for testing the login box: %w", err) } clientID = client.GetClientID() } @@ -119,7 +118,7 @@ Fetch an access token for the given client and API. if clientID == "" { client, err := getOrCreateCLITesterClient(cli.api.Client) if err != nil { - return errors.New("Unable to fetch a token; please check your internet connection and verify you haven't reached your apps limit") + return fmt.Errorf("Unable to create an app to test getting a token: %w", err) } clientID = client.GetClientID() }