-
Notifications
You must be signed in to change notification settings - Fork 938
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
feat(cli): add error message for bad login URL #4042
Conversation
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) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
a9bd76c
to
0782811
Compare
@@ -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) |
There was a problem hiding this comment.
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.
cc @deansheather ready for another review |
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: