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

CLI-18: customize error messages for test command #115

Merged
merged 4 commits into from
Feb 27, 2021
Merged
Changes from 3 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
17 changes: 9 additions & 8 deletions internal/cli/test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cli

import (
"errors"
"fmt"

"github.com/auth0/auth0-cli/internal/ansi"
Expand Down Expand Up @@ -46,14 +47,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 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()
}

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 {
Expand All @@ -70,7 +71,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: %w", clientID, err)
}

if err := ansi.Spinner("Fetching user metadata", func() error {
Expand All @@ -79,7 +80,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: %w", err)
}

fmt.Fprint(cli.renderer.MessageWriter, "\n")
Expand Down Expand Up @@ -118,14 +119,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 errors.New("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()
Expand All @@ -140,7 +141,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: %w", clientID, err)
}

fmt.Fprint(cli.renderer.MessageWriter, "\n")
Expand All @@ -162,7 +163,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: %w", clientID, err)
}

fmt.Fprint(cli.renderer.MessageWriter, "\n")
Expand Down