mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Fix account store silently failing (#13956)
* Fix account store silently failing * Combine calls * undo
This commit is contained in:
@@ -38,19 +38,21 @@ export default class AccountStore implements IAccountStore {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAccountsByProvider(providerId: string): Promise<azdata.Account[]> {
|
public async getAccountsByProvider(providerId: string): Promise<azdata.Account[]> {
|
||||||
return this.doOperation(() => {
|
const accounts = await this.doOperation(async () => {
|
||||||
return this.readFromMemento()
|
await this.cleanupDeprecatedAccounts();
|
||||||
.then(accounts => accounts.filter(account => account.key.providerId === providerId));
|
const accounts = await this.readFromMemento();
|
||||||
|
return accounts.filter(account => account.key.providerId === providerId);
|
||||||
});
|
});
|
||||||
|
return accounts ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public getAllAccounts(): Promise<azdata.Account[]> {
|
public async getAllAccounts(): Promise<azdata.Account[]> {
|
||||||
return this.doOperation(() => {
|
const accounts = await this.doOperation(async () => {
|
||||||
return this.cleanupDeprecatedAccounts().then(() => {
|
await this.cleanupDeprecatedAccounts();
|
||||||
return this.readFromMemento();
|
return this.readFromMemento();
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
return accounts ?? [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public cleanupDeprecatedAccounts(): Promise<void> {
|
public cleanupDeprecatedAccounts(): Promise<void> {
|
||||||
@@ -114,16 +116,16 @@ export default class AccountStore implements IAccountStore {
|
|||||||
target.isStale = source.isStale;
|
target.isStale = source.isStale;
|
||||||
}
|
}
|
||||||
|
|
||||||
private doOperation<T>(op: () => Promise<T>) {
|
private doOperation<T>(op: () => Promise<T>): Promise<T | undefined> {
|
||||||
// Initialize the active operation to an empty promise if necessary
|
// Initialize the active operation to an empty promise if necessary
|
||||||
let activeOperation = this._activeOperation || Promise.resolve<any>(null);
|
let activeOperation = this._activeOperation || Promise.resolve();
|
||||||
|
|
||||||
// Chain the operation to perform to the end of the existing promise
|
// Chain the operation to perform to the end of the existing promise
|
||||||
activeOperation = activeOperation.then(op);
|
activeOperation = activeOperation.then(op);
|
||||||
|
|
||||||
// Add a catch at the end to make sure we can continue after any errors
|
// Add a catch at the end to make sure we can continue after any errors
|
||||||
activeOperation = activeOperation.then(undefined, (err) => {
|
activeOperation = activeOperation.then(undefined, err => {
|
||||||
// TODO: Log the error
|
this.logService.error(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Point the current active operation to this one
|
// Point the current active operation to this one
|
||||||
|
|||||||
Reference in New Issue
Block a user