From 22e49c431698cafe6827cbfb34cf489461c2c86b Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Wed, 14 Sep 2022 13:15:47 -0700 Subject: [PATCH] feat(cli): add error message for bad login URL (#4042) --- cli/login.go | 2 +- cli/login_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cli/login.go b/cli/login.go index a178c34ca2..dfc35fcc9e 100644 --- a/cli/login.go +++ b/cli/login.go @@ -83,7 +83,7 @@ func login() *cobra.Command { hasInitialUser, err := client.HasFirstUser(cmd.Context()) if err != nil { - return xerrors.Errorf("has initial user: %w", err) + return xerrors.Errorf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser? Error - has initial user: %w", serverURL.String(), err) } if !hasInitialUser { _, _ = fmt.Fprintf(cmd.OutOrStdout(), caret+"Your Coder deployment hasn't been set up!\n") diff --git a/cli/login_test.go b/cli/login_test.go index 1a6c502b78..8ff6673dda 100644 --- a/cli/login_test.go +++ b/cli/login_test.go @@ -2,6 +2,7 @@ package cli_test import ( "context" + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -23,6 +24,15 @@ func TestLogin(t *testing.T) { require.Error(t, err) }) + t.Run("InitialUserBadLoginURL", func(t *testing.T) { + t.Parallel() + badLoginURL := "https://fcca2077f06e68aaf9" + root, _ := clitest.New(t, "login", badLoginURL) + err := root.Execute() + errMsg := fmt.Sprintf("Failed to check server %q for first user, is the URL correct and is coder accessible from your browser?", badLoginURL) + require.ErrorContains(t, err, errMsg) + }) + t.Run("InitialUserTTY", func(t *testing.T) { t.Parallel() client := coderdtest.New(t, nil)