Skip to content

Conversation

@miguel-figueiredoPT
Copy link

@miguel-figueiredoPT miguel-figueiredoPT commented Dec 22, 2025

This PR implements a change on the CLI - When logging in, catch UnauthorizedException and fetch the login status from it.

Resolution for issue: #224

@miguel-figueiredoPT miguel-figueiredoPT force-pushed the feature/224-fix-cli-login-error branch from 20f5769 to 599ec0c Compare December 22, 2025 17:14
Copy link
Contributor

@mgaffigan mgaffigan left a 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>
@miguel-figueiredoPT miguel-figueiredoPT force-pushed the feature/224-fix-cli-login-error branch from 71cc19c to 8e7a76a Compare December 22, 2025 17:33
mgaffigan
mgaffigan previously approved these changes Dec 22, 2025
Signed-off-by: miguelfigueiredo <miguelsfigueiredo90@gmail.com>
Signed-off-by: miguelfigueiredo <miguelsfigueiredo90@gmail.com>
mgaffigan
mgaffigan previously approved these changes Dec 23, 2025
Signed-off-by: miguelfigueiredo <miguelsfigueiredo90@gmail.com>
@tonygermano tonygermano linked an issue Dec 23, 2025 that may be closed by this pull request
Copy link
Collaborator

@NicoPiel NicoPiel left a 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.

Copy link
Member

@tonygermano tonygermano left a 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.

Copy link
Member

@tonygermano tonygermano left a 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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return;
System.exit(77);

77 is the unix exit code for EX_NOPERM. This code is already using exit code 2 for usage errors.

Comment on lines +197 to 198
error("Could not login to server. Status: " + loginStatus.getStatus(), null);
return;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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.

@pacmano1 pacmano1 requested review from Copilot and removed request for gibson9583 and pacmano1 December 26, 2025 13:27
Copy link

Copilot AI left a 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 catch UnauthorizedException
  • Extracted LoginStatus from 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.

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.

oiecommand hangs after failed login attempt

4 participants