Enable no-floating-promises for azurecore (#16946)

* Enable no-floating-promises for azurecore

* few more

* fix compile
This commit is contained in:
Charles Gagnon
2021-09-02 09:20:32 -07:00
committed by GitHub
parent b27bdb0027
commit f35576ae7f
19 changed files with 71 additions and 48 deletions

View File

@@ -27,7 +27,7 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
const enablePreviewFeatures = vscode.workspace.getConfiguration('workbench').get('enablePreviewFeatures');
if (!enablePreviewFeatures) {
const msg = localize('azure.cloudTerminalPreview', "You must enable preview features in order to use Azure Cloud Shell.");
vscode.window.showInformationMessage(msg);
void vscode.window.showInformationMessage(msg);
return;
}
let azureAccount: AzureAccount | undefined;
@@ -41,7 +41,7 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
const action = await vscode.window.showErrorMessage(localize('azure.noAccountError', "You are not currently signed into any Azure accounts, Please sign in and then try again."),
signin);
if (action === signin) {
vscode.commands.executeCommand('azure.resource.signin');
void vscode.commands.executeCommand('azure.resource.signin');
}
return;
} else if (accounts.length === 1) {
@@ -52,7 +52,7 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
placeHolder: localize('azure.pickAnAzureAccount', "Select an Azure account")
});
if (!pickedAccount) {
vscode.window.showErrorMessage(localize('azure.accountNotSelectedError', "You must select an Azure account for this feature to work."));
void vscode.window.showErrorMessage(localize('azure.accountNotSelectedError', "You must select an Azure account for this feature to work."));
return;
}
azureAccount = accounts.find(acct => acct.displayInfo.displayName === pickedAccount);
@@ -64,7 +64,7 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
const listOfTenants = azureAccount.properties.tenants.map(t => t.displayName);
if (listOfTenants.length === 0) {
vscode.window.showErrorMessage(localize('azure.noTenants', "A tenant is required for this feature. Your Azure subscription seems to have no tenants."));
void vscode.window.showErrorMessage(localize('azure.noTenants', "A tenant is required for this feature. Your Azure subscription seems to have no tenants."));
return;
}
@@ -78,7 +78,7 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
const pickedTenant = await vscode.window.showQuickPick(listOfTenants, { canPickMany: false });
if (!pickedTenant) {
vscode.window.showErrorMessage(localize('azure.mustPickTenant', "You must select a tenant for this feature to work."));
void vscode.window.showErrorMessage(localize('azure.mustPickTenant', "You must select a tenant for this feature to work."));
return;
}
@@ -89,7 +89,7 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
await terminalService.getOrCreateCloudConsole(azureAccount, tenant);
} catch (ex) {
console.error(ex);
vscode.window.showErrorMessage(ex);
void vscode.window.showErrorMessage(ex);
}
});
@@ -114,7 +114,7 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
subscriptions = await subscriptionService.getSubscriptions(account);
} catch (error) {
account.isStale = true;
vscode.window.showErrorMessage(AzureResourceErrorMessageUtil.getErrorMessage(error));
void vscode.window.showErrorMessage(AzureResourceErrorMessageUtil.getErrorMessage(error));
return;
}
}
@@ -162,15 +162,15 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
});
vscode.commands.registerCommand('azure.resource.azureview.refresh', async (node?: TreeNode) => {
await azureViewTree.refresh(node, true);
return azureViewTree.refresh(node, true);
});
vscode.commands.registerCommand('azure.resource.connectiondialog.refresh', async (node?: TreeNode) => {
await connectionDialogTree.refresh(node, true);
return connectionDialogTree.refresh(node, true);
});
vscode.commands.registerCommand('azure.resource.signin', async (node?: TreeNode) => {
vscode.commands.executeCommand('workbench.actions.modal.linkedAccount');
return vscode.commands.executeCommand('workbench.actions.modal.linkedAccount');
});
vscode.commands.registerCommand('azure.resource.connectsqlserver', async (node?: TreeNode | azdata.ObjectExplorerContext) => {
@@ -191,7 +191,7 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
const conn = await azdata.connection.openConnectionDialog(undefined, connectionProfile, { saveConnection: true, showDashboard: true });
if (conn) {
vscode.commands.executeCommand('workbench.view.connections');
void vscode.commands.executeCommand('workbench.view.connections');
}
});
@@ -205,6 +205,6 @@ export function registerAzureResourceCommands(appContext: AppContext, azureViewT
}
const urlToOpen = `${connectionProfile.azurePortalEndpoint}//${connectionProfile.azureTenantId}/#resource/${connectionProfile.azureResourceId}`;
vscode.env.openExternal(vscode.Uri.parse(urlToOpen));
await vscode.env.openExternal(vscode.Uri.parse(urlToOpen));
});
}

View File

@@ -33,7 +33,7 @@ export interface IAzureResourceCacheService {
get<T>(key: string): T | undefined;
update<T>(key: string, value: T): void;
update<T>(key: string, value: T): Promise<void>;
}

View File

@@ -22,8 +22,8 @@ export class AzureResourceCacheService implements IAzureResourceCacheService {
return this._context.workspaceState.get(key);
}
public update<T>(key: string, value: T): void {
this._context.workspaceState.update(key, value);
public async update<T>(key: string, value: T): Promise<void> {
await this._context.workspaceState.update(key, value);
}
private _context: ExtensionContext = undefined;

View File

@@ -45,7 +45,7 @@ export class AzureResourceSubscriptionFilterService implements IAzureResourceSub
selectedSubscriptionsCache[account.key.accountId] = selectedSubscriptions;
this._cacheService.update<AzureResourceSelectedSubscriptionsCache>(this._cacheKey, { selectedSubscriptions: selectedSubscriptionsCache });
await this._cacheService.update<AzureResourceSelectedSubscriptionsCache>(this._cacheKey, { selectedSubscriptions: selectedSubscriptionsCache });
const filters: string[] = [];
for (const accountId in selectedSubscriptionsCache) {

View File

@@ -47,7 +47,7 @@ export class AzureResourceSubscriptionService implements IAzureResourceSubscript
const errorMsg = localize('azure.resource.tenantSubscriptionsError', "Failed to get subscriptions for account {0} (tenant '{1}'). {2}", account.key.accountId, tenantId, AzureResourceErrorMessageUtil.getErrorMessage(error));
console.warn(errorMsg);
errors.push(error);
vscode.window.showWarningMessage(errorMsg);
void vscode.window.showWarningMessage(errorMsg);
}
}
if (!gotSubscriptions) {

View File

@@ -37,7 +37,7 @@ const handleNeverUsed = async (): Promise<void> => {
const option = await vscode.window.showInformationMessage<TerminalMessageItem>(neverUsedString, openAzureShellButton, okButton);
if (option.action === TerminalOption.OPEN_SITE) {
vscode.env.openExternal(vscode.Uri.parse('https://aka.ms/AA83f8f'));
void vscode.env.openExternal(vscode.Uri.parse('https://aka.ms/AA83f8f'));
}
};
@@ -115,7 +115,7 @@ export class AzureTerminalService implements IAzureTerminalService {
});
if (!shell) {
vscode.window.showErrorMessage(localize('azure.shellTypeRequired', "You must pick a shell type"));
void vscode.window.showErrorMessage(localize('azure.shellTypeRequired', "You must pick a shell type"));
return;
}
@@ -236,7 +236,7 @@ class AzureTerminal implements vscode.Pseudoterminal {
const terminalUri = terminalResult.data?.socketUri;
if (terminalResult.data.error) {
vscode.window.showErrorMessage(terminalResult.data.error.message);
void vscode.window.showErrorMessage(terminalResult.data.error.message);
}
if (!terminalUri) {

View File

@@ -44,7 +44,7 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
if (this._isClearingCache) {
subscriptions = await this._subscriptionService.getSubscriptions(this.account);
this.updateCache<azureResource.AzureResourceSubscription[]>(subscriptions);
await this.updateCache<azureResource.AzureResourceSubscription[]>(subscriptions);
this._isClearingCache = false;
} else {
subscriptions = await this.getCachedSubscriptions();
@@ -77,7 +77,7 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
errMsg = AzureResourceErrorMessageUtil.getErrorMessage(err);
}
if (!token) {
vscode.window.showWarningMessage(localize('azure.unableToAccessSubscription', "Unable to access subscription {0} ({1}). Please [refresh the account](command:azure.resource.signin) to try again. {2}", s.name, s.id, errMsg));
void vscode.window.showWarningMessage(localize('azure.unableToAccessSubscription', "Unable to access subscription {0} ({1}). Please [refresh the account](command:azure.resource.signin) to try again. {2}", s.name, s.id, errMsg));
return false;
}
return true;
@@ -91,7 +91,7 @@ export class AzureResourceAccountTreeNode extends AzureResourceContainerTreeNode
}
} catch (error) {
if (error instanceof AzureSubscriptionError) {
vscode.commands.executeCommand('azure.resource.signin');
void vscode.commands.executeCommand('azure.resource.signin');
}
return [AzureResourceMessageTreeNode.create(AzureResourceErrorMessageUtil.getErrorMessage(error), this)];
}

View File

@@ -45,8 +45,8 @@ export abstract class AzureResourceContainerTreeNodeBase extends AzureResourceTr
this._cacheKey = this._cacheService.generateKey(id);
}
protected updateCache<T>(cache: T): void {
this._cacheService.update<T>(this._cacheKey, cache);
protected updateCache<T>(cache: T): Promise<void> {
return this._cacheService.update<T>(this._cacheKey, cache);
}
protected getCache<T>(): T {

View File

@@ -70,9 +70,9 @@ export class ConnectionDialogTreeProvider implements vscode.TreeDataProvider<Tre
}
if (errorMessages.length > 0) {
const showAccountsAction = localize('azure.resource.tree.treeProvider.openAccountsDialog', "Show Azure accounts");
vscode.window.showErrorMessage(localize('azure.resource.tree.treeProvider.accountLoadError', "Failed to load some Azure accounts. {0}", errorMessages.join(',')), showAccountsAction).then(result => {
void vscode.window.showErrorMessage(localize('azure.resource.tree.treeProvider.accountLoadError', "Failed to load some Azure accounts. {0}", errorMessages.join(',')), showAccountsAction).then(result => {
if (result === showAccountsAction) {
vscode.commands.executeCommand('azure.resource.signin');
void vscode.commands.executeCommand('azure.resource.signin');
}
});
}

View File

@@ -68,7 +68,7 @@ export class FlatAccountTreeNode extends AzureResourceContainerTreeNodeBase {
public async getChildren(): Promise<TreeNode[]> {
if (this._isClearingCache) {
this._loader.start();
this._loader.start().catch(err => console.error('Error loading Azure FlatAccountTreeNodes ', err));
this._isClearingCache = false;
return [];
} else {
@@ -211,12 +211,12 @@ class FlatAccountTreeNodeLoader {
}
} catch (error) {
if (error instanceof AzureSubscriptionError) {
vscode.commands.executeCommand('azure.resource.signin');
void vscode.commands.executeCommand('azure.resource.signin');
}
// http status code 429 means "too many requests"
// use a custom error message for azure resource graph api throttling error to make it more actionable for users.
const errorMessage = error?.statusCode === 429 ? localize('azure.resource.throttleerror', "Requests from this account have been throttled. To retry, please select a smaller number of subscriptions.") : AzureResourceErrorMessageUtil.getErrorMessage(error);
vscode.window.showErrorMessage(localize('azure.resource.tree.loadresourceerror', "An error occurred while loading Azure resources: {0}", errorMessage));
void vscode.window.showErrorMessage(localize('azure.resource.tree.loadresourceerror', "An error occurred while loading Azure resources: {0}", errorMessage));
}
this._isLoading = false;

View File

@@ -40,7 +40,7 @@ export class FlatAzureResourceTreeProvider implements vscode.TreeDataProvider<Tr
}
if (this.resourceLoader.state === LoaderState.NotStarted) {
this.resourceLoader.start();
this.resourceLoader.start().catch(err => console.error('Error loading Azure Resources for FlatAzureResourceTreeProvider ', err));
return [AzureResourceMessageTreeNode.create(localize('azure.resource.tree.treeProvider.loadingLabel', "Loading ..."), undefined)];
}