diff --git a/src/sql/platform/accounts/common/accountStore.ts b/src/sql/platform/accounts/common/accountStore.ts index 080ef6b819..4b1cc37c8d 100644 --- a/src/sql/platform/accounts/common/accountStore.ts +++ b/src/sql/platform/accounts/common/accountStore.ts @@ -38,19 +38,21 @@ export default class AccountStore implements IAccountStore { }); } - public getAccountsByProvider(providerId: string): Promise { - return this.doOperation(() => { - return this.readFromMemento() - .then(accounts => accounts.filter(account => account.key.providerId === providerId)); + public async getAccountsByProvider(providerId: string): Promise { + const accounts = await this.doOperation(async () => { + await this.cleanupDeprecatedAccounts(); + const accounts = await this.readFromMemento(); + return accounts.filter(account => account.key.providerId === providerId); }); + return accounts ?? []; } - public getAllAccounts(): Promise { - return this.doOperation(() => { - return this.cleanupDeprecatedAccounts().then(() => { - return this.readFromMemento(); - }); + public async getAllAccounts(): Promise { + const accounts = await this.doOperation(async () => { + await this.cleanupDeprecatedAccounts(); + return this.readFromMemento(); }); + return accounts ?? []; } public cleanupDeprecatedAccounts(): Promise { @@ -114,16 +116,16 @@ export default class AccountStore implements IAccountStore { target.isStale = source.isStale; } - private doOperation(op: () => Promise) { + private doOperation(op: () => Promise): Promise { // Initialize the active operation to an empty promise if necessary - let activeOperation = this._activeOperation || Promise.resolve(null); + let activeOperation = this._activeOperation || Promise.resolve(); // Chain the operation to perform to the end of the existing promise activeOperation = activeOperation.then(op); // Add a catch at the end to make sure we can continue after any errors - activeOperation = activeOperation.then(undefined, (err) => { - // TODO: Log the error + activeOperation = activeOperation.then(undefined, err => { + this.logService.error(err); }); // Point the current active operation to this one