mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 01:25:38 -05:00
More dangling promise cleanup (#8518)
* More dangling promise cleanup * return void * Function to async * Fix a couple missed promises
This commit is contained in:
@@ -84,7 +84,7 @@ export class ConfigureDashboardAction extends Task {
|
||||
});
|
||||
}
|
||||
|
||||
runTask(accessor: ServicesAccessor): Promise<void> {
|
||||
return accessor.get(IOpenerService).open(URI.parse(ConfigureDashboardAction.configHelpUri)).then();
|
||||
async runTask(accessor: ServicesAccessor): Promise<void> {
|
||||
accessor.get(IOpenerService).open(URI.parse(ConfigureDashboardAction.configHelpUri));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ export class TaskHistoryView extends Disposable {
|
||||
}
|
||||
|
||||
private updateTask(task: TaskNode): void {
|
||||
this._tree.refresh(task);
|
||||
this._tree.refresh(task).catch(err => errors.onUnexpectedError(err));
|
||||
}
|
||||
|
||||
public refreshTree(): void {
|
||||
|
||||
@@ -57,12 +57,12 @@ export class ScriptAction extends Action {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(element: TaskNode): Promise<boolean> {
|
||||
public async run(element: TaskNode): Promise<boolean> {
|
||||
if (element instanceof TaskNode) {
|
||||
if (element.script && element.script !== '') {
|
||||
this._queryEditorService.newSqlEditor(element.script);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import { IOpenerService } from 'vs/platform/opener/common/opener';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
import { firstIndex } from 'vs/base/common/arrays';
|
||||
import { values } from 'vs/base/common/collections';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
export class AccountManagementService implements IAccountManagementService {
|
||||
// CONSTANTS ///////////////////////////////////////////////////////////
|
||||
@@ -314,8 +315,8 @@ export class AccountManagementService implements IAccountManagementService {
|
||||
* Copy the user code to the clipboard and open a browser to the verification URI
|
||||
*/
|
||||
public copyUserCodeAndOpenBrowser(userCode: string, uri: string): void {
|
||||
this._clipboardService.writeText(userCode);
|
||||
this._openerService.open(URI.parse(uri));
|
||||
this._clipboardService.writeText(userCode).catch(err => onUnexpectedError(err));
|
||||
this._openerService.open(URI.parse(uri)).catch(err => onUnexpectedError(err));
|
||||
}
|
||||
|
||||
// SERVICE MANAGEMENT METHODS //////////////////////////////////////////
|
||||
|
||||
@@ -59,7 +59,7 @@ export class BackupUiService implements IBackupUiService {
|
||||
}
|
||||
}
|
||||
|
||||
public showBackupDialog(connection: IConnectionProfile): Promise<void> {
|
||||
public async showBackupDialog(connection: IConnectionProfile): Promise<void> {
|
||||
let self = this;
|
||||
self._connectionUri = ConnectionUtils.generateUri(connection);
|
||||
self._currentProvider = connection.providerName;
|
||||
@@ -79,31 +79,27 @@ export class BackupUiService implements IBackupUiService {
|
||||
}
|
||||
|
||||
let backupOptions = this.getOptions(this._currentProvider);
|
||||
return new Promise<void>((resolve) => {
|
||||
let uri = this._connectionManagementService.getConnectionUri(connection)
|
||||
+ ProviderConnectionInfo.idSeparator
|
||||
+ ConnectionUtils.ConnectionUriBackupIdAttributeName
|
||||
+ ProviderConnectionInfo.nameValueSeparator
|
||||
+ BackupUiService._connectionUniqueId;
|
||||
let uri = this._connectionManagementService.getConnectionUri(connection)
|
||||
+ ProviderConnectionInfo.idSeparator
|
||||
+ ConnectionUtils.ConnectionUriBackupIdAttributeName
|
||||
+ ProviderConnectionInfo.nameValueSeparator
|
||||
+ BackupUiService._connectionUniqueId;
|
||||
|
||||
this._connectionUri = uri;
|
||||
this._connectionUri = uri;
|
||||
|
||||
BackupUiService._connectionUniqueId++;
|
||||
BackupUiService._connectionUniqueId++;
|
||||
|
||||
// Create connection if needed
|
||||
if (!this._connectionManagementService.isConnected(uri)) {
|
||||
this._connectionManagementService.connect(connection, uri).then(() => {
|
||||
this._onShowBackupEvent.fire({ connection: connection, ownerUri: uri });
|
||||
});
|
||||
}
|
||||
if (backupOptions) {
|
||||
(backupDialog as OptionsDialog).open(backupOptions, self._optionValues);
|
||||
} else {
|
||||
(backupDialog as BackupDialog).open(connection);
|
||||
}
|
||||
|
||||
if (backupOptions) {
|
||||
(backupDialog as OptionsDialog).open(backupOptions, self._optionValues);
|
||||
} else {
|
||||
(backupDialog as BackupDialog).open(connection);
|
||||
}
|
||||
resolve(void 0);
|
||||
});
|
||||
// Create connection if needed
|
||||
if (!this._connectionManagementService.isConnected(uri)) {
|
||||
await this._connectionManagementService.connect(connection, uri);
|
||||
this._onShowBackupEvent.fire({ connection: connection, ownerUri: uri });
|
||||
}
|
||||
}
|
||||
|
||||
public onShowBackupDialog() {
|
||||
|
||||
@@ -18,6 +18,7 @@ import { IConnectionProviderRegistry, Extensions as ConnectionExtensions } from
|
||||
import { ICapabilitiesService, ProviderFeatures, clientCapabilities, ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
import { entries } from 'sql/base/common/collections';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
const connectionRegistry = Registry.as<IConnectionProviderRegistry>(ConnectionExtensions.ConnectionProviderContributions);
|
||||
|
||||
@@ -71,7 +72,7 @@ export class CapabilitiesService extends Disposable implements ICapabilitiesServ
|
||||
|
||||
extensionService.whenInstalledExtensionsRegistered().then(() => {
|
||||
this.cleanupProviders();
|
||||
});
|
||||
}).catch(err => onUnexpectedError(err));
|
||||
|
||||
_storageService.onWillSaveState(() => this.shutdown());
|
||||
|
||||
@@ -85,7 +86,7 @@ export class CapabilitiesService extends Disposable implements ICapabilitiesServ
|
||||
let id = extension.contributes[connectionProvider].providerId;
|
||||
delete this.capabilities.connectionProviderCache[id];
|
||||
}
|
||||
});
|
||||
}).catch(err => onUnexpectedError(err));
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import { IConfigurationService } from 'vs/platform/configuration/common/configur
|
||||
import { CmsConnectionController } from 'sql/workbench/services/connection/browser/cmsConnectionController';
|
||||
import { entries } from 'sql/base/common/collections';
|
||||
import { find } from 'vs/base/common/arrays';
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
|
||||
export interface IConnectionValidateResult {
|
||||
isValid: boolean;
|
||||
@@ -181,12 +182,12 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
profile.savePassword = true;
|
||||
}
|
||||
|
||||
this.handleDefaultOnConnect(params, profile);
|
||||
this.handleDefaultOnConnect(params, profile).catch(err => onUnexpectedError(err));
|
||||
} else {
|
||||
profile.serverName = trim(profile.serverName);
|
||||
this._connectionManagementService.addSavedPassword(profile).then(connectionWithPassword => {
|
||||
this.handleDefaultOnConnect(params, connectionWithPassword);
|
||||
});
|
||||
this._connectionManagementService.addSavedPassword(profile).then(async (connectionWithPassword) => {
|
||||
await this.handleDefaultOnConnect(params, connectionWithPassword);
|
||||
}).catch(err => onUnexpectedError(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -219,14 +220,14 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
}
|
||||
}
|
||||
|
||||
private handleDefaultOnConnect(params: INewConnectionParams, connection: IConnectionProfile): Thenable<void> {
|
||||
private async handleDefaultOnConnect(params: INewConnectionParams, connection: IConnectionProfile): Promise<void> {
|
||||
if (this.ignoreNextConnect) {
|
||||
this._connectionDialog.resetConnection();
|
||||
this._connectionDialog.close();
|
||||
this.ignoreNextConnect = false;
|
||||
this._connecting = false;
|
||||
this._dialogDeferredPromise.resolve(connection);
|
||||
return Promise.resolve();
|
||||
return;
|
||||
}
|
||||
let fromEditor = params && params.connectionType === ConnectionType.editor;
|
||||
let isTemporaryConnection = params && params.connectionType === ConnectionType.temporary;
|
||||
@@ -242,7 +243,8 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
showFirewallRuleOnError: true
|
||||
};
|
||||
|
||||
return this._connectionManagementService.connectAndSaveProfile(connection, uri, options, params && params.input).then(connectionResult => {
|
||||
try {
|
||||
const connectionResult = await this._connectionManagementService.connectAndSaveProfile(connection, uri, options, params && params.input);
|
||||
this._connecting = false;
|
||||
if (connectionResult && connectionResult.connected) {
|
||||
this._connectionDialog.close();
|
||||
@@ -255,11 +257,11 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
this._connectionDialog.resetConnection();
|
||||
this.showErrorDialog(Severity.Error, this._connectionErrorTitle, connectionResult.errorMessage, connectionResult.callStack);
|
||||
}
|
||||
}).catch(err => {
|
||||
} catch (err) {
|
||||
this._connecting = false;
|
||||
this._connectionDialog.resetConnection();
|
||||
this.showErrorDialog(Severity.Error, this._connectionErrorTitle, err);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private get uiController(): IConnectionComponentController {
|
||||
@@ -339,7 +341,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
this._model = this.createModel(connectionWithPassword);
|
||||
|
||||
this.uiController.fillInConnectionInputs(this._model);
|
||||
});
|
||||
}).catch(err => onUnexpectedError(err));
|
||||
this._connectionDialog.updateProvider(this._providerNameToDisplayNameMap[connectionInfo.providerName]);
|
||||
}
|
||||
|
||||
@@ -381,12 +383,9 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
return newProfile;
|
||||
}
|
||||
|
||||
private showDialogWithModel(): Promise<void> {
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
this.updateModelServerCapabilities(this._inputModel);
|
||||
this.doShowDialog(this._params);
|
||||
resolve(null);
|
||||
});
|
||||
private async showDialogWithModel(): Promise<void> {
|
||||
this.updateModelServerCapabilities(this._inputModel);
|
||||
await this.doShowDialog(this._params);
|
||||
}
|
||||
|
||||
public openDialogAndWait(
|
||||
@@ -438,7 +437,7 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
});
|
||||
}
|
||||
|
||||
private doShowDialog(params: INewConnectionParams): Promise<void> {
|
||||
private async doShowDialog(params: INewConnectionParams): Promise<void> {
|
||||
if (!this._connectionDialog) {
|
||||
this._connectionDialog = this._instantiationService.createInstance(ConnectionDialogWidget, this._providerDisplayNames, this._providerNameToDisplayNameMap[this._model.providerName], this._providerNameToDisplayNameMap);
|
||||
this._connectionDialog.onCancel(() => {
|
||||
@@ -457,12 +456,10 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
this._connectionDialog.newConnectionParams = params;
|
||||
this._connectionDialog.updateProvider(this._providerNameToDisplayNameMap[this._currentProviderType]);
|
||||
|
||||
return new Promise<void>(() => {
|
||||
const recentConnections: ConnectionProfile[] = this._connectionManagementService.getRecentConnections(params.providers);
|
||||
this._connectionDialog.open(recentConnections.length > 0);
|
||||
this.uiController.focusOnOpen();
|
||||
recentConnections.forEach(conn => conn.dispose());
|
||||
});
|
||||
const recentConnections: ConnectionProfile[] = this._connectionManagementService.getRecentConnections(params.providers);
|
||||
await this._connectionDialog.open(recentConnections.length > 0);
|
||||
this.uiController.focusOnOpen();
|
||||
recentConnections.forEach(conn => conn.dispose());
|
||||
}
|
||||
|
||||
private showErrorDialog(severity: Severity, headerTitle: string, message: string, messageDetails?: string): void {
|
||||
@@ -477,16 +474,15 @@ export class ConnectionDialogService implements IConnectionDialogService {
|
||||
localize('kerberosHelpLink', "Help configuring Kerberos is available at {0}", helpLink),
|
||||
localize('kerberosKinit', "If you have previously connected you may need to re-run kinit.")
|
||||
].join('\r\n');
|
||||
actions.push(new Action('Kinit', 'Run kinit', null, true, () => {
|
||||
actions.push(new Action('Kinit', 'Run kinit', null, true, async () => {
|
||||
this._connectionDialog.close();
|
||||
this._clipboardService.writeText('kinit\r');
|
||||
this._commandService.executeCommand('workbench.action.terminal.focus').then(resolve => {
|
||||
// setTimeout to allow for terminal Instance to load.
|
||||
setTimeout(() => {
|
||||
return this._commandService.executeCommand('workbench.action.terminal.paste');
|
||||
}, 10);
|
||||
}).then(resolve => null, reject => null);
|
||||
return null;
|
||||
await this._clipboardService.writeText('kinit\r');
|
||||
await this._commandService.executeCommand('workbench.action.terminal.focus');
|
||||
// setTimeout to allow for terminal Instance to load.
|
||||
setTimeout(() => {
|
||||
return this._commandService.executeCommand('workbench.action.terminal.paste');
|
||||
}, 10);
|
||||
return;
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
@@ -214,35 +214,32 @@ suite('SQL ConnectionManagementService tests', () => {
|
||||
|
||||
}
|
||||
|
||||
function connect(uri: string, options?: IConnectionCompletionOptions, fromDialog?: boolean, connection?: IConnectionProfile, error?: string, errorCode?: number, errorCallStack?: string): Promise<IConnectionResult> {
|
||||
async function connect(uri: string, options?: IConnectionCompletionOptions, fromDialog?: boolean, connection?: IConnectionProfile, error?: string, errorCode?: number, errorCallStack?: string): Promise<IConnectionResult> {
|
||||
let connectionToUse = connection ? connection : connectionProfile;
|
||||
return new Promise<IConnectionResult>((resolve, reject) => {
|
||||
let id = connectionToUse.getOptionsKey();
|
||||
let defaultUri = 'connection:' + (id ? id : connectionToUse.serverName + ':' + connectionToUse.databaseName);
|
||||
connectionManagementService.onConnectionRequestSent(() => {
|
||||
let info: azdata.ConnectionInfoSummary = {
|
||||
connectionId: error ? undefined : 'id',
|
||||
connectionSummary: {
|
||||
databaseName: connectionToUse.databaseName,
|
||||
serverName: connectionToUse.serverName,
|
||||
userName: connectionToUse.userName
|
||||
},
|
||||
errorMessage: error,
|
||||
errorNumber: errorCode,
|
||||
messages: errorCallStack,
|
||||
ownerUri: uri ? uri : defaultUri,
|
||||
serverInfo: undefined
|
||||
};
|
||||
connectionManagementService.onConnectionComplete(0, info);
|
||||
});
|
||||
connectionManagementService.cancelConnectionForUri(uri).then(() => {
|
||||
if (fromDialog) {
|
||||
resolve(connectionManagementService.connectAndSaveProfile(connectionToUse, uri, options));
|
||||
} else {
|
||||
resolve(connectionManagementService.connect(connectionToUse, uri, options));
|
||||
}
|
||||
});
|
||||
let id = connectionToUse.getOptionsKey();
|
||||
let defaultUri = 'connection:' + (id ? id : connectionToUse.serverName + ':' + connectionToUse.databaseName);
|
||||
connectionManagementService.onConnectionRequestSent(() => {
|
||||
let info: azdata.ConnectionInfoSummary = {
|
||||
connectionId: error ? undefined : 'id',
|
||||
connectionSummary: {
|
||||
databaseName: connectionToUse.databaseName,
|
||||
serverName: connectionToUse.serverName,
|
||||
userName: connectionToUse.userName
|
||||
},
|
||||
errorMessage: error,
|
||||
errorNumber: errorCode,
|
||||
messages: errorCallStack,
|
||||
ownerUri: uri ? uri : defaultUri,
|
||||
serverInfo: undefined
|
||||
};
|
||||
connectionManagementService.onConnectionComplete(0, info);
|
||||
});
|
||||
await connectionManagementService.cancelConnectionForUri(uri);
|
||||
if (fromDialog) {
|
||||
return connectionManagementService.connectAndSaveProfile(connectionToUse, uri, options);
|
||||
} else {
|
||||
return connectionManagementService.connect(connectionToUse, uri, options);
|
||||
}
|
||||
}
|
||||
|
||||
test('showConnectionDialog should open the dialog with default type given no parameters', done => {
|
||||
|
||||
Reference in New Issue
Block a user