From 1699dd072982e9131d14009faddfc6cbc1737112 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Fri, 13 Mar 2020 11:19:25 -0700 Subject: [PATCH] Check for valid uri/resource (#9593) * Check for valid uri/resource * Add a few other cases --- src/sql/workbench/browser/taskUtilities.ts | 6 +++--- .../workbench/contrib/query/browser/flavorStatus.ts | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/sql/workbench/browser/taskUtilities.ts b/src/sql/workbench/browser/taskUtilities.ts index c03e82f6d1..155a0a8336 100644 --- a/src/sql/workbench/browser/taskUtilities.ts +++ b/src/sql/workbench/browser/taskUtilities.ts @@ -57,7 +57,7 @@ export function replaceConnection(oldUri: string, newUri: string, connectionServ * * @param topLevelOnly If true, only return top-level (i.e. connected) Object Explorer connections instead of database connections when appropriate */ -export function getCurrentGlobalConnection(objectExplorerService: IObjectExplorerService, connectionManagementService: IConnectionManagementService, workbenchEditorService: IEditorService, topLevelOnly: boolean = false): IConnectionProfile { +export function getCurrentGlobalConnection(objectExplorerService: IObjectExplorerService, connectionManagementService: IConnectionManagementService, workbenchEditorService: IEditorService, topLevelOnly: boolean = false): IConnectionProfile | undefined { let connection: IConnectionProfile; // object Explorer Connection let objectExplorerSelection = objectExplorerService.getSelectedProfileAndDatabase(); @@ -78,9 +78,9 @@ export function getCurrentGlobalConnection(objectExplorerService: IObjectExplore let activeInput = workbenchEditorService.activeEditor; if (activeInput) { // dashboard Connection - if (activeInput instanceof DashboardInput) { + if (activeInput instanceof DashboardInput && activeInput.uri) { connection = connectionManagementService.getConnectionProfile(activeInput.uri.toString()); - } else { + } else if (activeInput.resource) { // editor Connection connection = connectionManagementService.getConnectionProfile(activeInput.resource.toString()); } diff --git a/src/sql/workbench/contrib/query/browser/flavorStatus.ts b/src/sql/workbench/contrib/query/browser/flavorStatus.ts index 7d81ab0c33..1a2a768d74 100644 --- a/src/sql/workbench/contrib/query/browser/flavorStatus.ts +++ b/src/sql/workbench/contrib/query/browser/flavorStatus.ts @@ -96,12 +96,12 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont } private _onEditorClosed(event: IEditorCloseEvent): void { - let uri = event.editor.resource.toString(); + let uri = event.editor.resource?.toString(); if (uri && uri in this._sqlStatusEditors) { // If active editor is being closed, hide the query status. let activeEditor = this.editorService.activeEditorPane; if (activeEditor) { - let currentUri = activeEditor.input.resource.toString(); + let currentUri = activeEditor.input.resource?.toString(); if (uri === currentUri) { this.hide(); } @@ -114,7 +114,7 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont private _onEditorsChanged(): void { let activeEditor = this.editorService.activeEditorPane; if (activeEditor) { - let uri = activeEditor.input.resource.toString(); + let uri = activeEditor.input.resource?.toString(); // Show active editor's language flavor status if (uri) { @@ -145,7 +145,7 @@ export class SqlFlavorStatusbarItem extends Disposable implements IWorkbenchCont private _showStatus(uri: string): void { let activeEditor = this.editorService.activeEditorPane; if (activeEditor) { - let currentUri = activeEditor.input.resource.toString(); + let currentUri = activeEditor.input.resource?.toString(); if (uri === currentUri) { let flavor: SqlProviderEntry = this._sqlStatusEditors[uri]; if (flavor) { @@ -186,7 +186,7 @@ export class ChangeFlavorAction extends Action { public run(): Promise { let activeEditor = this._editorService.activeEditorPane; - let currentUri = activeEditor?.input.resource.toString(); + let currentUri = activeEditor?.input.resource?.toString(); if (this._connectionManagementService.isConnected(currentUri)) { let currentProvider = this._connectionManagementService.getProviderIdFromUri(currentUri); return this._showMessage(Severity.Info, nls.localize('alreadyConnected',