-
Notifications
You must be signed in to change notification settings - Fork 41
Bug - Fix CLI login error #231
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
base: main
Are you sure you want to change the base?
Bug - Fix CLI login error #231
Conversation
20f5769 to
599ec0c
Compare
mgaffigan
left a comment
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.
Omit the null check or handle at :192. Other comment is just a suggestion.
Signed-off-by: miguelfigueiredo <miguelsfigueiredo90@gmail.com>
Signed-off-by: miguelfigueiredo <miguelsfigueiredo90@gmail.com>
71cc19c to
8e7a76a
Compare
Signed-off-by: miguelfigueiredo <miguelsfigueiredo90@gmail.com>
Signed-off-by: miguelfigueiredo <miguelsfigueiredo90@gmail.com>
Signed-off-by: miguelfigueiredo <miguelsfigueiredo90@gmail.com>
NicoPiel
left a comment
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.
Looks good. Mitch already suggested the only change I would have made.
tonygermano
left a comment
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 was just testing, and this does resolve the uncaught exception, but the program still hangs after a failed login. We're going to need to dig a little more to see why the program is still not ending.
Looking at the error messages, I think the first one on line 191 is fine, because I can't think of a reason that we'd ever get a UnauthorizedException where the response wasn't a LoginStatus, so printing the stack trace would be useful there.
The second one on line 197 we might want to make a little more user-friendly, since that is the one that shows up for a bad password. I don't know that it's necessary to print the loginStatus, since we already know we have one, and it's not successful at this point. Perhaps a message like, Could not login to server. Please check your username and password and try again. would be more appropriate. This is similar to what was requested in the linked issue.
tonygermano
left a comment
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.
It was hanging because the client wasn't getting closed after the function returned, but I think it's better to return an appropriate exit code than to let it return 0 like it worked successfully since this can be used to run scripts as well as interactively.
|
|
||
| if (loginStatus.getStatus() != LoginStatus.Status.SUCCESS) { | ||
| error("Could not login to server.", null); | ||
| LoginStatus loginStatus; |
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.
| LoginStatus loginStatus; | |
| LoginStatus loginStatus = null; |
Changes below will complain that loginStatus may have not been initialized without this.
| } | ||
| else { | ||
| error("Could not login to server.", ex); | ||
| return; |
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.
| return; | |
| System.exit(77); |
77 is the unix exit code for EX_NOPERM. This code is already using exit code 2 for usage errors.
| error("Could not login to server. Status: " + loginStatus.getStatus(), null); | ||
| return; |
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.
| error("Could not login to server. Status: " + loginStatus.getStatus(), null); | |
| return; | |
| error("Could not login to server. Please check your username and password and try again.", null); | |
| System.exit(77); |
77 is the unix exit code for EX_NOPERM. This code is already using exit code 2 for usage errors.
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.
Pull request overview
This PR fixes a CLI login error handling issue by catching UnauthorizedException and extracting the LoginStatus from the exception's response. The fix addresses issue #224 where login failures were not properly handled.
Key Changes:
- Added exception handling around
client.login()to catchUnauthorizedException - Extracted
LoginStatusfrom the exception response using pattern matching - Improved error messaging to include the login status details
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This PR implements a change on the CLI - When logging in, catch UnauthorizedException and fetch the login status from it.
Resolution for issue: #224