Skip to content

feat(cli): add error message for bad login URL #4042

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

Merged
merged 1 commit into from
Sep 14, 2022

Conversation

jsjoeio
Copy link
Contributor

@jsjoeio jsjoeio commented Sep 13, 2022

This adds a more friendly error message when a user mistypes the user when running coder login <url>. Open to additional feedback/suggestions!

Fixes #3963

To test locally, run:

cd cli && go test -v -count 1 -run TestLogin/InitialUserBadLoginURL

@jsjoeio jsjoeio linked an issue Sep 13, 2022 that may be closed by this pull request
@jsjoeio jsjoeio self-assigned this Sep 13, 2022
@jsjoeio jsjoeio requested a review from a team September 13, 2022 18:23
cli/login.go Outdated
@@ -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: %w", serverURL.String(), err)
Copy link
Contributor Author

@jsjoeio jsjoeio Sep 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wish we could print this on two lines:
"friendly message..
error output...
"
but when I add \n it prints the error output twice. Any ideas @deansheather ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in that case you just write log output to stderr with your message and then return xerrors.Errorf("has initial user: %w", err) afterwards.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried fmt.Fprintln(cmd.ErrOrStderr(), errMsg) but then my test doesn't pass. Any pointers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked offline. I'll have it match the has initial user message.

@jsjoeio jsjoeio force-pushed the 3963-ux-better-error-message-for-coder-login-failure branch from a9bd76c to 0782811 Compare September 14, 2022 17:40
@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about this a bit more last night...Since this is user-facing, I think the friendly error message should be included in the test assertion. Otherwise, it can be removed and the test would still pass. Then we'd have a working CLI with poor UX. Instead, we want to ensure we have good UX.

@jsjoeio
Copy link
Contributor Author

jsjoeio commented Sep 14, 2022

cc @deansheather ready for another review

@jsjoeio jsjoeio enabled auto-merge (squash) September 14, 2022 17:49
@jsjoeio jsjoeio merged commit 22e49c4 into main Sep 14, 2022
@jsjoeio jsjoeio deleted the 3963-ux-better-error-message-for-coder-login-failure branch September 14, 2022 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ux: better error message for coder login failure
2 participants