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

@@ -0,0 +1,13 @@
{
"parserOptions": {
"project": "./extensions/azurecore/tsconfig.json"
},
"rules": {
"@typescript-eslint/no-floating-promises": [
"error",
{
"ignoreVoid": true
}
]
}
}

View File

@@ -104,7 +104,7 @@ export abstract class AzureAuth implements vscode.Disposable {
if (loginComplete) {
loginComplete.reject(ex);
} else {
vscode.window.showErrorMessage(ex.getPrintableString());
void vscode.window.showErrorMessage(ex.getPrintableString());
}
}
Logger.error(ex);
@@ -139,7 +139,7 @@ export abstract class AzureAuth implements vscode.Disposable {
return await this.hydrateAccount(tokenResult, this.getTokenClaims(tokenResult.token));
} catch (ex) {
if (ex instanceof AzureAuthError) {
vscode.window.showErrorMessage(ex.getPrintableString());
void vscode.window.showErrorMessage(ex.getPrintableString());
}
Logger.error(ex);
account.isStale = true;
@@ -616,7 +616,7 @@ export abstract class AzureAuth implements vscode.Disposable {
return this.deleteAccountCache(account);
} catch (ex) {
const msg = localize('azure.cacheErrrorRemove', "Error when removing your account from the cache.");
vscode.window.showErrorMessage(msg);
void vscode.window.showErrorMessage(msg);
Logger.error('Error when removing tokens.', ex);
}
}

View File

@@ -119,7 +119,7 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
}
private async _getSecurityToken(account: AzureAccount, resource: azdata.AzureResource): Promise<MultiTenantTokenResponse | undefined> {
vscode.window.showInformationMessage(localize('azure.deprecatedGetSecurityToken', "A call was made to azdata.accounts.getSecurityToken, this method is deprecated and will be removed in future releases. Please use getAccountSecurityToken instead."));
void vscode.window.showInformationMessage(localize('azure.deprecatedGetSecurityToken', "A call was made to azdata.accounts.getSecurityToken, this method is deprecated and will be removed in future releases. Please use getAccountSecurityToken instead."));
const azureAccount = account as AzureAccount;
const response: MultiTenantTokenResponse = {};
for (const tenant of azureAccount.properties.tenants) {
@@ -147,7 +147,7 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
if (this.authMappings.size === 0) {
Logger.log('No auth method was enabled.');
vscode.window.showErrorMessage(noAuthAvailable);
void vscode.window.showErrorMessage(noAuthAvailable);
return { canceled: true };
}
@@ -164,7 +164,7 @@ export class AzureAccountProvider implements azdata.AccountProvider, vscode.Disp
if (!pick) {
Logger.log('No auth method was selected.');
vscode.window.showErrorMessage(noAuthSelected);
void vscode.window.showErrorMessage(noAuthSelected);
return { canceled: true };
}

View File

@@ -58,7 +58,7 @@ export class AzureAccountProviderService implements vscode.Disposable {
AzureAccountProviderService.CommandClearTokenCache,
() => { self._event.emit(AzureAccountProviderService.CommandClearTokenCache); }
));
this._event.on(AzureAccountProviderService.CommandClearTokenCache, () => { self.onClearTokenCache(); });
this._event.on(AzureAccountProviderService.CommandClearTokenCache, () => { void self.onClearTokenCache(); });
// 1) Get a credential provider
// 2a) Store the credential provider for use later
@@ -98,11 +98,11 @@ export class AzureAccountProviderService implements vscode.Disposable {
.then(
() => {
let message = localize('clearTokenCacheSuccess', "Token cache successfully cleared");
vscode.window.showInformationMessage(`${loc.extensionName}: ${message}`);
void vscode.window.showInformationMessage(`${loc.extensionName}: ${message}`);
},
err => {
let message = localize('clearTokenCacheFailure', "Failed to clear token cache");
vscode.window.showErrorMessage(`${loc.extensionName}: ${message}: ${err}`);
void vscode.window.showErrorMessage(`${loc.extensionName}: ${message}: ${err}`);
});
}

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)];
}

View File

@@ -104,7 +104,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
await vscode.env.openExternal(vscode.Uri.parse(`${portalEndpoint}/#resource/subscriptions/${subscriptionId}/resourceGroups/${resourceGroup}/providers/${type}/${name}`));
} else {
console.log(`Missing required values - subscriptionId : ${subscriptionId} resourceGroup : ${resourceGroup} type: ${type} name: ${name}`);
vscode.window.showErrorMessage(loc.unableToOpenAzureLink);
void vscode.window.showErrorMessage(loc.unableToOpenAzureLink);
}
});
@@ -140,7 +140,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<azurec
return '';
}
}));
});
}).then(undefined, err => console.error('Error registering Azure ResourceDeployment value provider ', err));
return {
getSubscriptions(account?: azurecore.AzureAccount, ignoreErrors?: boolean, selectedOnly: boolean = false): Promise<azurecore.GetSubscriptionsResult> {

View File

@@ -24,7 +24,7 @@ describe('AccountProvider.SimpleWebServer', function (): void {
it('Double startup should fail', async function (): Promise<void> {
await server.startup();
server.startup().should.be.rejected();
await server.startup().should.be.rejected();
});
it('404 on unknown requests', async function (): Promise<void> {
@@ -59,7 +59,7 @@ describe('AccountProvider.SimpleWebServer', function (): void {
it('Server shuts off', async function (): Promise<void> {
await server.startup();
server.shutdown().should.not.be.rejected();
await server.shutdown().should.not.be.rejected();
});
});

View File

@@ -109,7 +109,10 @@ describe('AzureResourceAccountTreeNode.info', function (): void {
mockCacheService.setup((o) => o.generateKey(TypeMoq.It.isAnyString())).returns(() => generateGuid());
mockCacheService.setup((o) => o.get(TypeMoq.It.isAnyString())).returns(() => mockSubscriptionCache);
mockCacheService.setup((o) => o.update(TypeMoq.It.isAnyString(), TypeMoq.It.isAny())).returns(() => mockSubscriptionCache = mockSubscriptions);
mockCacheService.setup((o) => o.update(TypeMoq.It.isAnyString(), TypeMoq.It.isAny())).returns(() => {
mockSubscriptionCache = mockSubscriptions;
return Promise.resolve();
});
});
afterEach(function (): void {
@@ -217,7 +220,10 @@ describe('AzureResourceAccountTreeNode.getChildren', function (): void {
sinon.stub(azdata.accounts, 'getAccountSecurityToken').resolves(mockToken);
mockCacheService.setup((o) => o.generateKey(TypeMoq.It.isAnyString())).returns(() => generateGuid());
mockCacheService.setup((o) => o.get(TypeMoq.It.isAnyString())).returns(() => mockSubscriptionCache);
mockCacheService.setup((o) => o.update(TypeMoq.It.isAnyString(), TypeMoq.It.isAny())).returns(() => mockSubscriptionCache = mockSubscriptions);
mockCacheService.setup((o) => o.update(TypeMoq.It.isAnyString(), TypeMoq.It.isAny())).returns(() => {
mockSubscriptionCache = mockSubscriptions;
return Promise.resolve();
});
});
afterEach(function (): void {
@@ -354,7 +360,11 @@ describe('AzureResourceAccountTreeNode.clearCache', function (): void {
sinon.stub(azdata.accounts, 'getAccountSecurityToken').returns(Promise.resolve(mockToken));
mockCacheService.setup((o) => o.generateKey(TypeMoq.It.isAnyString())).returns(() => generateGuid());
mockCacheService.setup((o) => o.get(TypeMoq.It.isAnyString())).returns(() => mockSubscriptionCache);
mockCacheService.setup((o) => o.update(TypeMoq.It.isAnyString(), TypeMoq.It.isAny())).returns(() => mockSubscriptionCache = mockSubscriptions);
mockCacheService.setup((o) => o.update(TypeMoq.It.isAnyString(), TypeMoq.It.isAny())).returns(() =>
{
mockSubscriptionCache = mockSubscriptions;
return Promise.resolve();
});
});
afterEach(function (): void {

View File

@@ -59,7 +59,7 @@
"core-ci": "node --max_old_space_size=4095 ./node_modules/gulp/bin/gulp.js core-ci",
"extensions-ci": "node --max_old_space_size=4095 ./node_modules/gulp/bin/gulp.js extensions-ci",
"sqllint": "eslint --no-eslintrc -c .eslintrc.sql.ts.json --rulesdir ./build/lib/eslint --ext .ts ./src/sql",
"extensions-lint": "eslint --rulesdir ./build/lib/eslint --ext .ts ./extensions"
"extensions-lint": "eslint --rulesdir ./build/lib/eslint --ext .ts ./extensions/azurecore"
},
"dependencies": {
"@angular/animations": "~4.1.3",