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

Sm/aliases-without-config-file #842

Merged
merged 16 commits into from
Jun 1, 2023
Merged

Conversation

mshanemc
Copy link
Contributor

@mshanemc mshanemc commented May 26, 2023

What does this PR do?

stateAggregator.aliasAccessor without configFile.
every set/unset creates an fs operation with file locking (new library dependency, 3PP)
deprecate things that only AliasAccessor was using (aliasConfig, configGroup) to get to configFile
testSetup has special "mocks" for aliases now that they're not using configFile (they're actually real fs ops to the tmp dir)

this would be a breaking change to the public API because the inheritane chain from aliasAccessor contained a LOT of methods we aren't using and now it won't.

What issues does this PR fix or reference?

@W-12065678@ forcedotcom/cli#1806

@mshanemc mshanemc changed the base branch from main to sm/node16 May 26, 2023 16:35
Base automatically changed from sm/node16 to main May 28, 2023 20:48
@mshanemc mshanemc marked this pull request as ready for review May 30, 2023 17:09
@mshanemc mshanemc requested a review from shetzel May 30, 2023 17:10
try {
await unlock(this.fileLocation);
} catch {
// ignore the error. If it wasn't locked, that's what we wanted
Copy link
Contributor

Choose a reason for hiding this comment

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

Is that the only error that can happen when unlocking?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. I'll make the error specific to the reason I was doing this. There could be others that are fs related.

https://github.com/moxystudio/node-proper-lockfile/blob/9f8c303c91998e8404a911dc11c54029812bca69/lib/lockfile.js#LL285C83-L285C83

await this.saveAliasStoreToFile();
return;
}
if (useLock) await unlock(this.fileLocation);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an edge case, but seems possible:
lock throws an error that is not an ENOENT (maybe an EPERM error) so the lock is never obtained. In the catch we try to unlock and that throws an error, and is the one reported to the user. The user wouldn't know why the lock couldn't be obtained. To prevent this, we might need to use a try/catch/finally and the finally has a try/catch for the unlock.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think putting the original lock outside the try should surface an error better.

@shetzel
Copy link
Contributor

shetzel commented Jun 1, 2023

QA Notes:
I linked this branch to the plugin-org and plugin-settings plugins and ran a bunch of commands. Everything checked out.

alias list
alias set dh=foo
alias unset dh
alias set dh=foo dh1=bar dh2=baz
alias unset dh dh1 dh2
org create scratch -a dh (simultaneously with a similar command)

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.

2 participants