More promise cleanup (#8100)

* Some promise cleanup

* Handle more promise issues

* Remove changes that aren't needed anymore

* Use log service

* another one

* Be more explicit

* Some more promises cleaned up

* Handle promises here too

* Strings for errors

* Some more cleanup

* Remove unused imports
This commit is contained in:
Amir Omidi
2019-10-31 14:30:08 -07:00
committed by GitHub
parent 572a83dac7
commit b62c0cf2ab
11 changed files with 165 additions and 189 deletions

View File

@@ -10,6 +10,7 @@ import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/com
import { ConnectionController } from 'sql/workbench/services/connection/browser/connectionController';
import { CmsConnectionWidget } from 'sql/workbench/services/connection/browser/cmsConnectionWidget';
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
import { ILogService } from 'vs/platform/log/common/log';
/**
* Connection Controller for CMS Connections
@@ -22,9 +23,10 @@ export class CmsConnectionController extends ConnectionController {
providerName: string,
@IConnectionManagementService _connectionManagementService: IConnectionManagementService,
@IInstantiationService _instantiationService: IInstantiationService,
@IServerGroupController _serverGroupController: IServerGroupController
@IServerGroupController _serverGroupController: IServerGroupController,
@ILogService _logService: ILogService
) {
super(connectionProperties, callback, providerName, _connectionManagementService, _instantiationService, _serverGroupController);
super(connectionProperties, callback, providerName, _connectionManagementService, _instantiationService, _serverGroupController, _logService);
let specialOptions = this._providerOptions.filter(
(property) => (property.specialValueType !== null && property.specialValueType !== undefined));
this._connectionWidget = this._instantiationService.createInstance(CmsConnectionWidget, specialOptions, {

View File

@@ -16,6 +16,7 @@ import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHost
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
import { ConnectionWidget } from 'sql/workbench/services/connection/browser/connectionWidget';
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
import { ILogService } from 'vs/platform/log/common/log';
export class ConnectionController implements IConnectionComponentController {
private _advancedController: AdvancedPropertiesController;
@@ -33,7 +34,8 @@ export class ConnectionController implements IConnectionComponentController {
providerName: string,
@IConnectionManagementService protected readonly _connectionManagementService: IConnectionManagementService,
@IInstantiationService protected readonly _instantiationService: IInstantiationService,
@IServerGroupController protected readonly _serverGroupController: IServerGroupController
@IServerGroupController protected readonly _serverGroupController: IServerGroupController,
@ILogService private readonly _logService: ILogService
) {
this._callback = callback;
this._providerOptions = connectionProperties.connectionOptions;
@@ -52,7 +54,7 @@ export class ConnectionController implements IConnectionComponentController {
this._providerName = providerName;
}
protected onFetchDatabases(serverName: string, authenticationType: string, userName?: string, password?: string): Promise<string[]> {
protected async onFetchDatabases(serverName: string, authenticationType: string, userName?: string, password?: string): Promise<string[]> {
let tempProfile = this._model;
tempProfile.serverName = serverName;
tempProfile.authenticationType = authenticationType;
@@ -61,39 +63,35 @@ export class ConnectionController implements IConnectionComponentController {
tempProfile.groupFullName = '';
tempProfile.saveProfile = false;
let uri = this._connectionManagementService.getConnectionUri(tempProfile);
return new Promise<string[]>((resolve, reject) => {
if (this._databaseCache.has(uri)) {
let cachedDatabases: string[] = this._databaseCache.get(uri);
if (cachedDatabases !== null) {
resolve(cachedDatabases);
if (this._databaseCache.has(uri)) {
let cachedDatabases: string[] = this._databaseCache.get(uri);
if (cachedDatabases !== null) {
return cachedDatabases;
} else {
throw new Error('database cache didn\'t have value');
}
} else {
const connResult = await this._connectionManagementService.connect(tempProfile, uri);
if (connResult && connResult.connected) {
const result = await this._connectionManagementService.listDatabases(uri);
if (result && result.databaseNames) {
this._databaseCache.set(uri, result.databaseNames);
return result.databaseNames;
} else {
reject();
this._databaseCache.set(uri, null);
throw new Error('list databases failed');
}
} else {
this._connectionManagementService.connect(tempProfile, uri).then(connResult => {
if (connResult && connResult.connected) {
this._connectionManagementService.listDatabases(uri).then(result => {
if (result && result.databaseNames) {
this._databaseCache.set(uri, result.databaseNames);
resolve(result.databaseNames);
} else {
this._databaseCache.set(uri, null);
reject();
}
});
} else {
reject(connResult.errorMessage);
}
});
throw new Error(connResult.errorMessage);
}
});
}
}
protected onCreateNewServerGroup(): void {
this._serverGroupController.showCreateGroupDialog({
onAddGroup: (groupName) => this._connectionWidget.updateServerGroup(this.getAllServerGroups(), groupName),
onClose: () => this._connectionWidget.focusOnServerGroup()
});
}).catch((e) => this._logService.error(e));
}
protected handleonSetAzureTimeOut(): void {

View File

@@ -228,7 +228,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
*/
public onSessionCreated(handle: number, session: azdata.ObjectExplorerSession): void {
if (session && session.success) {
this.handleSessionCreated(session);
this.handleSessionCreated(session).catch((e) => this.logService.error(e));
} else {
let errorMessage = session && session.errorMessage ? session.errorMessage : errSessionCreateFailed;
this.logService.error(errorMessage);
@@ -283,7 +283,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
connection.isDisconnecting = true;
this._connectionManagementService.disconnect(connection).then((value) => {
connection.isDisconnecting = false;
});
}).catch((e) => this.logService.error(e));
});
}
}
@@ -346,7 +346,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
return new Promise<azdata.ObjectExplorerExpandInfo>((resolve, reject) => {
let provider = this._providers[providerId];
if (provider) {
TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.ObjectExplorerExpand, { refresh: 0, provider: providerId });
TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.ObjectExplorerExpand, { refresh: 0, provider: providerId }).catch((e) => this.logService.error(e));
this.expandOrRefreshNode(providerId, session, nodePath).then(result => {
resolve(result);
}, error => {
@@ -484,7 +484,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
public refreshNode(providerId: string, session: azdata.ObjectExplorerSession, nodePath: string): Thenable<azdata.ObjectExplorerExpandInfo> {
let provider = this._providers[providerId];
if (provider) {
TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.ObjectExplorerExpand, { refresh: 1, provider: providerId });
TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.ObjectExplorerExpand, { refresh: 1, provider: providerId }).catch((e) => this.logService.error(e));
return this.expandOrRefreshNode(providerId, session, nodePath, true);
}
return Promise.resolve(undefined);

View File

@@ -30,6 +30,7 @@ import { ILanguageSelection } from 'vs/editor/common/services/modeService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { ILogService } from 'vs/platform/log/common/log';
/**
* Service wrapper for opening and creating SQL documents as sql editor inputs
@@ -54,7 +55,8 @@ export class QueryEditorService implements IQueryEditorService {
@IInstantiationService private _instantiationService: IInstantiationService,
@IEditorService private _editorService: IEditorService,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IConfigurationService private _configurationService: IConfigurationService
@IConfigurationService private _configurationService: IConfigurationService,
@ILogService private _logService: ILogService
) {
}
@@ -139,7 +141,7 @@ export class QueryEditorService implements IQueryEditorService {
} else {
input.onConnectReject();
}
});
}).catch((e) => this._logService.error(e));
}
}
});