Skip to content
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

fix: add a did you mean action to AuthInfo #1079

Merged
merged 2 commits into from
Jun 7, 2024
Merged

Conversation

WillieRuemmele
Copy link
Member

What does this PR do?

adds a "did you mean" suggestion to the SfError thrown when we can't find a passed in username/alias when constructing an AuthInfo class.

What issues does this PR fix or reference?

@W-15921235@

@WillieRuemmele WillieRuemmele requested a review from a team as a code owner June 5, 2024 21:06
try {
await shouldThrow(AuthInfo.create({ username: '[email protected]', isDevHub: true }));
} catch (e) {
expect(e).to.have.property('name', expectedErrorName);
expect(e).to.have.property('message', 'No authorization information found for [email protected].');
expect(e).to.have.property('actions');
expect((e as SfError).actions).to.deep.equal([
Copy link
Member Author

Choose a reason for hiding this comment

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

this was failing to assert the actions[] was equal to the set array, had to break the assertion up

name: 'NamedOrgNotFoundError',
message: messages.getMessage('namedOrgNotFound', [username]),
actions: [
`It looks like you mistyped the username or alias. Did you mean "${findSuggestion(username, [
Copy link
Contributor

Choose a reason for hiding this comment

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

Could it be misleading to tell the user that they mistyped the username or alias? What happens if they provide a username or alias that simply doesn't exist?

Maybe simplifying it to just Did you mean "<suggestion>"? would be the most flexible

Also do we need to remove the action if no suggestion is found?

Copy link
Member Author

Choose a reason for hiding this comment

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

Juliet and I had some back and forth on this. We thought the current messaging was friendlier, but we also had exactly what you suggested 🤷‍♂️

I'll remove it if nothing is passed, or we couldn't deduce any similar names

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll happily defer to Juliet on the message 👍

message: messages.getMessage('namedOrgNotFound', [username]),
actions: [
`It looks like you mistyped the username or alias. Did you mean "${findSuggestion(username, [
...(await this.stateAggregator.orgs.list()).map((f) => f.split('.json')[0]),
Copy link
Contributor

Choose a reason for hiding this comment

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

is splitting the filename better than getting the username prop from the contents? Or can we not guarantee that that property will be there? More curious than anything

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, username is optional in the contents

@mdonnalley
Copy link
Contributor

QA

linked sfdx-core to plugin-org and linked plugin-org to sf

Aliases in my env:

Alias List
====================================================
| Alias             Value
| ───────────────── ────────────────────────────────
| 2862              [email protected]
| devhub            [email protected]
| qa                [email protected]
| gh2602            [email protected]
| na40devhub        [email protected]
| scratch-org       [email protected]
| my-org            [email protected]
| v61-custom-object [email protected]
| mdapi-temp-dir    [email protected]

🟢 sf org display -o devhb correctly suggests devhub

Error (2): Parsing --target-org
	No authorization information found for devhb.
See more help with --help

Try this:

It looks like you mistyped the username or alias. Did you mean "devhub"?

🟢 sf org display -o " "

Error (2): Parsing --target-org
	No authorization information found for  .
See more help with --help

Try this:

It looks like you mistyped the username or alias. Did you mean "qa"?

🟢 unset all aliases and then sf org display -o foo

Error (2): Parsing --target-org
	No authorization information found for foo.
See more help with --help

Try this:

It looks like you mistyped the username or alias. Did you mean "[email protected]"?

❓ What are your thoughts on making this a bit smarter? Seems weird to give a username suggestion when the user provided something that doesn't look like a username. Maybe we can check for @ in the string - or maybe that would come back to bite us in some other way?

🔴 unset all aliases and delete all orgs then sf org display -o foo

Error (2): Parsing --target-org
	No authorization information found for foo.
See more help with --help

Try this:

It looks like you mistyped the username or alias. Did you mean ""?

I'd expect this to not suggest anything

Copy link
Contributor

@mdonnalley mdonnalley left a comment

Choose a reason for hiding this comment

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

See QA

@mdonnalley
Copy link
Contributor

QA #2

🟢 no aliases and no orgs, sf org display -o foo

Error (2): Parsing --target-org
	No authorization information found for foo.
See more help with --help

@mdonnalley mdonnalley merged commit da5483e into main Jun 7, 2024
5 checks passed
@mdonnalley mdonnalley deleted the wr/didYouMeanAlias branch June 7, 2024 18:34
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.

3 participants