mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
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:
@@ -52,7 +52,7 @@ export class BreadcrumbComponent implements OnInit, OnDestroy {
|
|||||||
this._changeRef.detectChanges();
|
this._changeRef.detectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
public route(link: any[]): void {
|
public route(link: any[]): Promise<boolean> {
|
||||||
this._router.navigate(link);
|
return this._router.navigate(link);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,7 @@
|
|||||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||||
import * as types from 'vs/base/common/types';
|
import * as types from 'vs/base/common/types';
|
||||||
|
|
||||||
import * as azdata from 'azdata';
|
import * as azdata from 'azdata';
|
||||||
|
|
||||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||||
import { IRestoreService, IRestoreDialogController, TaskExecutionMode } from 'sql/platform/restore/common/restoreService';
|
import { IRestoreService, IRestoreDialogController, TaskExecutionMode } from 'sql/platform/restore/common/restoreService';
|
||||||
import { OptionsDialog } from 'sql/workbench/browser/modal/optionsDialog';
|
import { OptionsDialog } from 'sql/workbench/browser/modal/optionsDialog';
|
||||||
@@ -64,7 +62,7 @@ export class RestoreService implements IRestoreService {
|
|||||||
return new Promise<azdata.RestoreResponse>((resolve, reject) => {
|
return new Promise<azdata.RestoreResponse>((resolve, reject) => {
|
||||||
const providerResult = this.getProvider(connectionUri);
|
const providerResult = this.getProvider(connectionUri);
|
||||||
if (providerResult) {
|
if (providerResult) {
|
||||||
TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.RestoreRequested, { provider: providerResult.providerName });
|
TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.RestoreRequested, { provider: providerResult.providerName }).catch((e) => this.logService.error(e));
|
||||||
providerResult.provider.restore(connectionUri, restoreInfo).then(result => {
|
providerResult.provider.restore(connectionUri, restoreInfo).then(result => {
|
||||||
resolve(result);
|
resolve(result);
|
||||||
}, error => {
|
}, error => {
|
||||||
@@ -149,7 +147,8 @@ export class RestoreDialogController implements IRestoreDialogController {
|
|||||||
@IConnectionManagementService private _connectionService: IConnectionManagementService,
|
@IConnectionManagementService private _connectionService: IConnectionManagementService,
|
||||||
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
|
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
|
||||||
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
|
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
|
||||||
@ITaskService private _taskService: ITaskService
|
@ITaskService private _taskService: ITaskService,
|
||||||
|
@ILogService private _logService: ILogService,
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,11 +164,14 @@ export class RestoreDialogController implements IRestoreDialogController {
|
|||||||
const self = this;
|
const self = this;
|
||||||
let connectionProfile = self._connectionService.getConnectionProfile(self._ownerUri);
|
let connectionProfile = self._connectionService.getConnectionProfile(self._ownerUri);
|
||||||
let activeNode = self._objectExplorerService.getObjectExplorerNode(connectionProfile);
|
let activeNode = self._objectExplorerService.getObjectExplorerNode(connectionProfile);
|
||||||
this._taskService.onTaskComplete(response => {
|
this._taskService.onTaskComplete(async response => {
|
||||||
if (result.taskId === response.id && this.isSuccessfulRestore(response) && activeNode) {
|
if (result.taskId === response.id && this.isSuccessfulRestore(response) && activeNode) {
|
||||||
self._objectExplorerService.refreshTreeNode(activeNode.getSession(), activeNode).then(result => {
|
try {
|
||||||
self._objectExplorerService.getServerTreeView().refreshTree();
|
await self._objectExplorerService.refreshTreeNode(activeNode.getSession(), activeNode);
|
||||||
});
|
await self._objectExplorerService.getServerTreeView().refreshTree();
|
||||||
|
} catch (e) {
|
||||||
|
this._logService.error(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let restoreDialog = this._restoreDialogs[this._currentProvider];
|
let restoreDialog = this._restoreDialogs[this._currentProvider];
|
||||||
@@ -279,7 +281,7 @@ export class RestoreDialogController implements IRestoreDialogController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private handleOnClose(): void {
|
private handleOnClose(): void {
|
||||||
this._connectionService.disconnect(this._ownerUri);
|
this._connectionService.disconnect(this._ownerUri).catch((e) => this._logService.error(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleOnCancel(): void {
|
private handleOnCancel(): void {
|
||||||
|
|||||||
@@ -7,21 +7,18 @@ import { localize } from 'vs/nls';
|
|||||||
import { Action } from 'vs/base/common/actions';
|
import { Action } from 'vs/base/common/actions';
|
||||||
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
|
||||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
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 { ServerTreeView } from 'sql/workbench/parts/objectExplorer/browser/serverTreeView';
|
||||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||||
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
|
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 { ITree } from 'vs/base/parts/tree/browser/tree';
|
||||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
|
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
|
||||||
import { TreeNode } from 'sql/workbench/parts/objectExplorer/common/treeNode';
|
import { TreeNode } from 'sql/workbench/parts/objectExplorer/common/treeNode';
|
||||||
import Severity from 'vs/base/common/severity';
|
import Severity from 'vs/base/common/severity';
|
||||||
import { ObjectExplorerActionsContext } from 'sql/workbench/parts/objectExplorer/browser/objectExplorerActions';
|
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 { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
|
||||||
import { UNSAVED_GROUP_ID } from 'sql/platform/connection/common/constants';
|
import { UNSAVED_GROUP_ID } from 'sql/platform/connection/common/constants';
|
||||||
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
|
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
|
||||||
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
export class RefreshAction extends Action {
|
export class RefreshAction extends Action {
|
||||||
|
|
||||||
@@ -36,21 +33,21 @@ export class RefreshAction extends Action {
|
|||||||
private element: IConnectionProfile | TreeNode,
|
private element: IConnectionProfile | TreeNode,
|
||||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||||
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
|
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
|
||||||
@IErrorMessageService private _errorMessageService: IErrorMessageService
|
@IErrorMessageService private _errorMessageService: IErrorMessageService,
|
||||||
|
@ILogService private _logService: ILogService
|
||||||
) {
|
) {
|
||||||
super(id, label);
|
super(id, label);
|
||||||
this._tree = tree;
|
this._tree = tree;
|
||||||
}
|
}
|
||||||
public run(): Promise<boolean> {
|
public async run(): Promise<boolean> {
|
||||||
let treeNode: TreeNode;
|
let treeNode: TreeNode;
|
||||||
if (this.element instanceof ConnectionProfile) {
|
if (this.element instanceof ConnectionProfile) {
|
||||||
let connection: ConnectionProfile = this.element;
|
let connection: ConnectionProfile = this.element;
|
||||||
if (this._connectionManagementService.isConnected(undefined, connection)) {
|
if (this._connectionManagementService.isConnected(undefined, connection)) {
|
||||||
treeNode = this._objectExplorerService.getObjectExplorerNode(connection);
|
treeNode = this._objectExplorerService.getObjectExplorerNode(connection);
|
||||||
if (treeNode === undefined) {
|
if (treeNode === undefined) {
|
||||||
this._objectExplorerService.updateObjectExplorerNodes(connection.toIConnectionProfile()).then(() => {
|
await this._objectExplorerService.updateObjectExplorerNodes(connection.toIConnectionProfile());
|
||||||
treeNode = this._objectExplorerService.getObjectExplorerNode(connection);
|
treeNode = this._objectExplorerService.getObjectExplorerNode(connection);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (this.element instanceof TreeNode) {
|
} else if (this.element instanceof TreeNode) {
|
||||||
@@ -58,26 +55,26 @@ export class RefreshAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (treeNode) {
|
if (treeNode) {
|
||||||
return this._tree.collapse(this.element).then(() => {
|
try {
|
||||||
return this._objectExplorerService.refreshTreeNode(treeNode.getSession(), treeNode).then(() => {
|
await this._tree.collapse(this.element);
|
||||||
|
try {
|
||||||
return this._tree.refresh(this.element).then(() => {
|
await this._objectExplorerService.refreshTreeNode(treeNode.getSession(), treeNode);
|
||||||
return this._tree.expand(this.element);
|
} catch (error) {
|
||||||
}, refreshError => {
|
|
||||||
return Promise.resolve(true);
|
|
||||||
});
|
|
||||||
}, error => {
|
|
||||||
this.showError(error);
|
this.showError(error);
|
||||||
return Promise.resolve(true);
|
return true;
|
||||||
});
|
|
||||||
}, collapseError => {
|
|
||||||
return Promise.resolve(true);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return Promise.resolve(true);
|
await this._tree.refresh(this.element);
|
||||||
|
return this._tree.expand(this.element);
|
||||||
|
} catch (ex) {
|
||||||
|
this._logService.error(ex);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private showError(errorMessage: string) {
|
private showError(errorMessage: string) {
|
||||||
|
this._logService.error(errorMessage);
|
||||||
if (this._errorMessageService) {
|
if (this._errorMessageService) {
|
||||||
this._errorMessageService.showDialog(Severity.Error, '', errorMessage);
|
this._errorMessageService.showDialog(Severity.Error, '', errorMessage);
|
||||||
}
|
}
|
||||||
@@ -99,29 +96,23 @@ export class DisconnectConnectionAction extends Action {
|
|||||||
super(id, label);
|
super(id, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
run(actionContext: ObjectExplorerActionsContext): Promise<any> {
|
async run(actionContext: ObjectExplorerActionsContext): Promise<any> {
|
||||||
return new Promise<boolean>((resolve, reject) => {
|
|
||||||
if (!this._connectionProfile) {
|
if (!this._connectionProfile) {
|
||||||
resolve(true);
|
return true;
|
||||||
}
|
}
|
||||||
if (this._connectionManagementService.isProfileConnected(this._connectionProfile)) {
|
if (this._connectionManagementService.isProfileConnected(this._connectionProfile)) {
|
||||||
let profileImpl = this._connectionProfile as ConnectionProfile;
|
let profileImpl = this._connectionProfile as ConnectionProfile;
|
||||||
if (profileImpl) {
|
if (profileImpl) {
|
||||||
profileImpl.isDisconnecting = true;
|
profileImpl.isDisconnecting = true;
|
||||||
}
|
}
|
||||||
this._connectionManagementService.disconnect(this._connectionProfile).then((value) => {
|
await this._connectionManagementService.disconnect(this._connectionProfile);
|
||||||
if (profileImpl) {
|
if (profileImpl) {
|
||||||
profileImpl.isDisconnecting = false;
|
profileImpl.isDisconnecting = false;
|
||||||
}
|
}
|
||||||
resolve(true);
|
return true;
|
||||||
}
|
|
||||||
).catch(disconnectError => {
|
|
||||||
reject(disconnectError);
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
resolve(true);
|
return true;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +132,7 @@ export class AddServerAction extends Action {
|
|||||||
this.class = 'add-server-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 : {
|
let connection: IConnectionProfile = element === undefined ? undefined : {
|
||||||
connectionName: undefined,
|
connectionName: undefined,
|
||||||
serverName: undefined,
|
serverName: undefined,
|
||||||
@@ -159,8 +150,8 @@ export class AddServerAction extends Action {
|
|||||||
saveProfile: true,
|
saveProfile: true,
|
||||||
id: element.id
|
id: element.id
|
||||||
};
|
};
|
||||||
this._connectionManagementService.showConnectionDialog(undefined, undefined, connection);
|
await this._connectionManagementService.showConnectionDialog(undefined, undefined, connection);
|
||||||
return Promise.resolve(true);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -180,9 +171,9 @@ export class AddServerGroupAction extends Action {
|
|||||||
this.class = 'add-server-group-action';
|
this.class = 'add-server-group-action';
|
||||||
}
|
}
|
||||||
|
|
||||||
public run(): Promise<boolean> {
|
public async run(): Promise<boolean> {
|
||||||
this.serverGroupController.showCreateGroupDialog();
|
await this.serverGroupController.showCreateGroupDialog();
|
||||||
return Promise.resolve(true);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import { UNSAVED_GROUP_ID, mssqlProviderName } from 'sql/platform/connection/com
|
|||||||
import { $ } from 'vs/base/browser/dom';
|
import { $ } from 'vs/base/browser/dom';
|
||||||
import { OEManageConnectionAction } from 'sql/workbench/parts/dashboard/browser/dashboardActions';
|
import { OEManageConnectionAction } from 'sql/workbench/parts/dashboard/browser/dashboardActions';
|
||||||
import { IViewsService, IView, ViewContainer, IViewDescriptorCollection } from 'vs/workbench/common/views';
|
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', () => {
|
suite('SQL Connection Tree Action tests', () => {
|
||||||
let errorMessageService: TypeMoq.Mock<TestErrorMessageService>;
|
let errorMessageService: TypeMoq.Mock<TestErrorMessageService>;
|
||||||
@@ -43,6 +43,8 @@ suite('SQL Connection Tree Action tests', () => {
|
|||||||
callStack: undefined
|
callStack: undefined
|
||||||
};
|
};
|
||||||
let capabilitiesService = new TestCapabilitiesService();
|
let capabilitiesService = new TestCapabilitiesService();
|
||||||
|
const logService = new ConsoleLogService();
|
||||||
|
|
||||||
setup(() => {
|
setup(() => {
|
||||||
errorMessageService = TypeMoq.Mock.ofType(TestErrorMessageService, TypeMoq.MockBehavior.Loose);
|
errorMessageService = TypeMoq.Mock.ofType(TestErrorMessageService, TypeMoq.MockBehavior.Loose);
|
||||||
let nothing: void;
|
let nothing: void;
|
||||||
@@ -427,7 +429,8 @@ suite('SQL Connection Tree Action tests', () => {
|
|||||||
connection,
|
connection,
|
||||||
connectionManagementService.object,
|
connectionManagementService.object,
|
||||||
objectExplorerService.object,
|
objectExplorerService.object,
|
||||||
undefined);
|
undefined,
|
||||||
|
logService);
|
||||||
|
|
||||||
connectionAction.run().then((value) => {
|
connectionAction.run().then((value) => {
|
||||||
connectionManagementService.verify(x => x.isConnected(undefined, TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());
|
connectionManagementService.verify(x => x.isConnected(undefined, TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());
|
||||||
@@ -514,7 +517,8 @@ suite('SQL Connection Tree Action tests', () => {
|
|||||||
connection,
|
connection,
|
||||||
connectionManagementService.object,
|
connectionManagementService.object,
|
||||||
objectExplorerService.object,
|
objectExplorerService.object,
|
||||||
undefined);
|
undefined,
|
||||||
|
logService);
|
||||||
|
|
||||||
connectionAction.run().then((value) => {
|
connectionAction.run().then((value) => {
|
||||||
connectionManagementService.verify(x => x.isConnected(undefined, TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());
|
connectionManagementService.verify(x => x.isConnected(undefined, TypeMoq.It.isAny()), TypeMoq.Times.atLeastOnce());
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import { Trace } from 'vs/platform/instantiation/common/instantiationService';
|
|||||||
import { values } from 'vs/base/common/map';
|
import { values } from 'vs/base/common/map';
|
||||||
import { IModuleFactory, IBootstrapParams } from 'sql/workbench/services/bootstrap/common/bootstrapParams';
|
import { IModuleFactory, IBootstrapParams } from 'sql/workbench/services/bootstrap/common/bootstrapParams';
|
||||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||||
|
import { ILogService } from 'vs/platform/log/common/log';
|
||||||
|
|
||||||
const selectorCounter = new Map<string, number>();
|
const selectorCounter = new Map<string, number>();
|
||||||
|
|
||||||
@@ -64,6 +65,15 @@ export function bootstrapAngular<T>(service: IInstantiationService, moduleType:
|
|||||||
if (callbackSetModule) {
|
if (callbackSetModule) {
|
||||||
callbackSetModule(moduleRef);
|
callbackSetModule(moduleRef);
|
||||||
}
|
}
|
||||||
|
}).catch((e) => {
|
||||||
|
service.invokeFunction((accessor) => {
|
||||||
|
const logService = accessor.get(ILogService);
|
||||||
|
if (!logService) {
|
||||||
|
console.error(e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logService.error(e);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
return uniqueSelectorString;
|
return uniqueSelectorString;
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
|
|||||||
this._serverTreeView.deleteObjectExplorerNodeAndRefreshTree(connection).then(() => {
|
this._serverTreeView.deleteObjectExplorerNodeAndRefreshTree(connection).then(() => {
|
||||||
this.sendUpdateNodeEvent(connection, session.errorMessage);
|
this.sendUpdateNodeEvent(connection, session.errorMessage);
|
||||||
connection.isDisconnecting = true;
|
connection.isDisconnecting = true;
|
||||||
this._connectionManagementService.disconnect(connection).then((value) => {
|
this._connectionManagementService.disconnect(connection).then(() => {
|
||||||
connection.isDisconnecting = false;
|
connection.isDisconnecting = false;
|
||||||
}).catch((e) => this.logService.error(e));
|
}).catch((e) => this.logService.error(e));
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user