Skip to content

feat: improve CLI error messages #6778

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 11 commits into from
Mar 28, 2023
Merged

feat: improve CLI error messages #6778

merged 11 commits into from
Mar 28, 2023

Conversation

ammario
Copy link
Member

@ammario ammario commented Mar 24, 2023

Before clibase:
Screen Shot 2023-03-24 at 12 37 48 PM

clibase:
Screen Shot 2023-03-24 at 12 38 22 PM

now:
image

@ammario ammario requested a review from kylecarbs March 24, 2023 17:57
@ammario ammario marked this pull request as ready for review March 24, 2023 17:57
@ammario ammario enabled auto-merge (squash) March 24, 2023 17:57
Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

I agree that the original error for login is pretty bad, but I don't think reformatting it improves it, it's just a bad message to begin with (which is a side-effect of how it's implemented). It should simply have said Unable to reach "https://dev.coder.con", is the URL correct and is Coder accessible from your browser? (i.e. mainly omit the first user part and the detailed error part).

We could have a --debug flag that prints more detailed error messages.

Errors from the API still seem a bit messy:

❯ /tmp/coder ssh list
ERROR
GET http://127.0.0.1:3000/api/v2/workspaces?q=owner%3Ame: unexpected status code 401: You are signed out or your session has expired. Please sign in again to continue.: Try logging in using 'coder login <url>'.
    Error: API key expired at "2023-03-21 15:14:13.352559 +0000 UTC".

They were better before:

❯ coder list
You are signed out or your session has expired. Please sign in again to continue. Try logging in using 'coder login <url>'.
Run 'coder list --help' for usage.

Unless debugging, the expiry date isn't very useful, and the status code is pretty much useless since the human message already says it. I think keeping the error message mostly to a single line is good for CLI users too.

Personally I think the formatting doesn't really help here either:

❯ /tmp/coder ssh test -G
ERROR
upload GPG public keys and ownertrust to workspace
─────
export local ownertrust from GPG
─────
`gpg --export-ownertrust` failed: stderr: gpg: Fatal: can't open '/home/mafredri/.gnupg/trustdb.gpg': No such file or directory

stdout:

exit status 2
─────
exit status 2
─────

But the original wasn't good either:

❯ coder ssh test -G
upload GPG public keys and ownertrust to workspace: export local ownertrust from GPG: `gpg --export-ownertrust` failed: stderr: gpg: Fatal: can't open '/home/mafredri/.gnupg/trustdb.gpg': No such file or directory

stdout:

exit status 2: exit status 2
Run 'coder ssh --help' for usage.

Original feels less busy though, but obviously stdout should be discarded since it's empty (and likely always), as should the double exit status.

@ammario
Copy link
Member Author

ammario commented Mar 24, 2023

kk.. I got rid of decoration:

image

and simplified in cases where we have a codersdk.Error:
Screen Shot 2023-03-24 at 3 38 58 PM

@ammario
Copy link
Member Author

ammario commented Mar 24, 2023

I want to avoid changing the errors themselves in this PR and just get us to a state where we feel they're as good as they were before clibase.

@ammario
Copy link
Member Author

ammario commented Mar 24, 2023

Screen Shot 2023-03-24 at 4 16 02 PM

Per slack poll, it's now on one line

@ammario ammario requested review from mafredri and removed request for kylecarbs March 24, 2023 21:16
@mafredri
Copy link
Member

Looks better 👍🏻, thanks.

I do seem to have a knack for finding these problems though. Might be good to verify what the behavior is for a few more commands:

❯ /tmp/coder tokens ls
You are signed out or your session has expired. Please sign in again to continue.Try logging in using 'coder login <url>'.: You are signed out or your session has expired. Please sign in again to continue.Try logging in using 'coder login <url>'.

I.e. duplicated message and continue.Try without space.

And weird long-indent for second exit code 🤔

❯ /tmp/coder ssh test -G
upload GPG public keys and ownertrust to workspace: export local ownertrust from GPG: `gpg --export-ownertrust` failed: stderr: gpg: Fatal: can't open '/home/mafredri/.gnupg/trustdb.gpg': No such file or directory

stdout:

exit status 2:                                                                                                                 exit status 2

@ammario
Copy link
Member Author

ammario commented Mar 24, 2023

Good catch. We'll need golden files for errors soon...

Fixed both by removing the unnecessary recursion in the error formatter.. c9e31bb

Copy link
Member

@mafredri mafredri left a comment

Choose a reason for hiding this comment

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

LGTM!

// only show the SDK error on the top of the stack.
msg = sdkError.Message
if sdkError.Helper != "" {
msg = msg + "\n" + sdkError.Helper
Copy link
Member

Choose a reason for hiding this comment

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

The newline here makes sense and makes this look nice. 👍🏻

@ammario ammario merged commit 1176256 into main Mar 28, 2023
@ammario ammario deleted the cli-errors branch March 28, 2023 16:03
@github-actions github-actions bot locked and limited conversation to collaborators Mar 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants