Some promise fixes (#8216)

* Some promise fixes

* changes to how we're logging errors

* Fix the tests

* Fix a few other issues
This commit is contained in:
Amir Omidi
2019-11-05 11:50:39 -08:00
committed by GitHub
parent 5a392dfd58
commit 1b88c10197
6 changed files with 73 additions and 66 deletions

View File

@@ -7,21 +7,18 @@ import { localize } from 'vs/nls';
import { Action } from 'vs/base/common/actions';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
import { ServerTreeView } from 'sql/workbench/parts/objectExplorer/browser/serverTreeView';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
import { ITree } from 'vs/base/parts/tree/browser/tree';
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
import { TreeNode } from 'sql/workbench/parts/objectExplorer/common/treeNode';
import Severity from 'vs/base/common/severity';
import { ObjectExplorerActionsContext } from 'sql/workbench/parts/objectExplorer/browser/objectExplorerActions';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
import { UNSAVED_GROUP_ID } from 'sql/platform/connection/common/constants';
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
import { ILogService } from 'vs/platform/log/common/log';
export class RefreshAction extends Action {
@@ -36,21 +33,21 @@ export class RefreshAction extends Action {
private element: IConnectionProfile | TreeNode,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
@IErrorMessageService private _errorMessageService: IErrorMessageService
@IErrorMessageService private _errorMessageService: IErrorMessageService,
@ILogService private _logService: ILogService
) {
super(id, label);
this._tree = tree;
}
public run(): Promise<boolean> {
public async run(): Promise<boolean> {
let treeNode: TreeNode;
if (this.element instanceof ConnectionProfile) {
let connection: ConnectionProfile = this.element;
if (this._connectionManagementService.isConnected(undefined, connection)) {
treeNode = this._objectExplorerService.getObjectExplorerNode(connection);
if (treeNode === undefined) {
this._objectExplorerService.updateObjectExplorerNodes(connection.toIConnectionProfile()).then(() => {
treeNode = this._objectExplorerService.getObjectExplorerNode(connection);
});
await this._objectExplorerService.updateObjectExplorerNodes(connection.toIConnectionProfile());
treeNode = this._objectExplorerService.getObjectExplorerNode(connection);
}
}
} else if (this.element instanceof TreeNode) {
@@ -58,26 +55,26 @@ export class RefreshAction extends Action {
}
if (treeNode) {
return this._tree.collapse(this.element).then(() => {
return this._objectExplorerService.refreshTreeNode(treeNode.getSession(), treeNode).then(() => {
return this._tree.refresh(this.element).then(() => {
return this._tree.expand(this.element);
}, refreshError => {
return Promise.resolve(true);
});
}, error => {
try {
await this._tree.collapse(this.element);
try {
await this._objectExplorerService.refreshTreeNode(treeNode.getSession(), treeNode);
} catch (error) {
this.showError(error);
return Promise.resolve(true);
});
}, collapseError => {
return Promise.resolve(true);
});
return true;
}
await this._tree.refresh(this.element);
return this._tree.expand(this.element);
} catch (ex) {
this._logService.error(ex);
return true;
}
}
return Promise.resolve(true);
return true;
}
private showError(errorMessage: string) {
this._logService.error(errorMessage);
if (this._errorMessageService) {
this._errorMessageService.showDialog(Severity.Error, '', errorMessage);
}
@@ -99,29 +96,23 @@ export class DisconnectConnectionAction extends Action {
super(id, label);
}
run(actionContext: ObjectExplorerActionsContext): Promise<any> {
return new Promise<boolean>((resolve, reject) => {
if (!this._connectionProfile) {
resolve(true);
async run(actionContext: ObjectExplorerActionsContext): Promise<any> {
if (!this._connectionProfile) {
return true;
}
if (this._connectionManagementService.isProfileConnected(this._connectionProfile)) {
let profileImpl = this._connectionProfile as ConnectionProfile;
if (profileImpl) {
profileImpl.isDisconnecting = true;
}
if (this._connectionManagementService.isProfileConnected(this._connectionProfile)) {
let profileImpl = this._connectionProfile as ConnectionProfile;
if (profileImpl) {
profileImpl.isDisconnecting = true;
}
this._connectionManagementService.disconnect(this._connectionProfile).then((value) => {
if (profileImpl) {
profileImpl.isDisconnecting = false;
}
resolve(true);
}
).catch(disconnectError => {
reject(disconnectError);
});
} else {
resolve(true);
await this._connectionManagementService.disconnect(this._connectionProfile);
if (profileImpl) {
profileImpl.isDisconnecting = false;
}
});
return true;
} else {
return true;
}
}
}
@@ -141,7 +132,7 @@ export class AddServerAction extends Action {
this.class = 'add-server-action';
}
public run(element: ConnectionProfileGroup): Promise<boolean> {
public async run(element: ConnectionProfileGroup): Promise<boolean> {
let connection: IConnectionProfile = element === undefined ? undefined : {
connectionName: undefined,
serverName: undefined,
@@ -159,8 +150,8 @@ export class AddServerAction extends Action {
saveProfile: true,
id: element.id
};
this._connectionManagementService.showConnectionDialog(undefined, undefined, connection);
return Promise.resolve(true);
await this._connectionManagementService.showConnectionDialog(undefined, undefined, connection);
return true;
}
}
@@ -180,9 +171,9 @@ export class AddServerGroupAction extends Action {
this.class = 'add-server-group-action';
}
public run(): Promise<boolean> {
this.serverGroupController.showCreateGroupDialog();
return Promise.resolve(true);
public async run(): Promise<boolean> {
await this.serverGroupController.showCreateGroupDialog();
return true;
}
}

View File

@@ -32,7 +32,7 @@ import { UNSAVED_GROUP_ID, mssqlProviderName } from 'sql/platform/connection/com
import { $ } from 'vs/base/browser/dom';
import { OEManageConnectionAction } from 'sql/workbench/parts/dashboard/browser/dashboardActions';
import { IViewsService, IView, ViewContainer, IViewDescriptorCollection } from 'vs/workbench/common/views';
import { ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { ConsoleLogService } from 'vs/platform/log/common/log';
suite('SQL Connection Tree Action tests', () => {
let errorMessageService: TypeMoq.Mock<TestErrorMessageService>;
@@ -43,6 +43,8 @@ suite('SQL Connection Tree Action tests', () => {
callStack: undefined
};
let capabilitiesService = new TestCapabilitiesService();
const logService = new ConsoleLogService();
setup(() => {
errorMessageService = TypeMoq.Mock.ofType(TestErrorMessageService, TypeMoq.MockBehavior.Loose);
let nothing: void;
@@ -427,7 +429,8 @@ suite('SQL Connection Tree Action tests', () => {
connection,
connectionManagementService.object,
objectExplorerService.object,
undefined);
undefined,
logService);
connectionAction.run().then((value) => {
connectionManagementService.verify(x => x.isConnected(undefined, TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());
@@ -514,7 +517,8 @@ suite('SQL Connection Tree Action tests', () => {
connection,
connectionManagementService.object,
objectExplorerService.object,
undefined);
undefined,
logService);
connectionAction.run().then((value) => {
connectionManagementService.verify(x => x.isConnected(undefined, TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());

View File

@@ -11,6 +11,7 @@ import { Trace } from 'vs/platform/instantiation/common/instantiationService';
import { values } from 'vs/base/common/map';
import { IModuleFactory, IBootstrapParams } from 'sql/workbench/services/bootstrap/common/bootstrapParams';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { ILogService } from 'vs/platform/log/common/log';
const selectorCounter = new Map<string, number>();
@@ -64,6 +65,15 @@ export function bootstrapAngular<T>(service: IInstantiationService, moduleType:
if (callbackSetModule) {
callbackSetModule(moduleRef);
}
}).catch((e) => {
service.invokeFunction((accessor) => {
const logService = accessor.get(ILogService);
if (!logService) {
console.error(e);
return;
}
logService.error(e);
});
});
return uniqueSelectorString;

View File

@@ -281,7 +281,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
this._serverTreeView.deleteObjectExplorerNodeAndRefreshTree(connection).then(() => {
this.sendUpdateNodeEvent(connection, session.errorMessage);
connection.isDisconnecting = true;
this._connectionManagementService.disconnect(connection).then((value) => {
this._connectionManagementService.disconnect(connection).then(() => {
connection.isDisconnecting = false;
}).catch((e) => this.logService.error(e));
});