From dcd952b9032a06f153e12eb7c404e06aba3c98f5 Mon Sep 17 00:00:00 2001 From: Charles Gagnon Date: Fri, 16 Apr 2021 09:24:22 -0700 Subject: [PATCH] Fix error when disconnecting database (#15146) * Fix error when disconnecting database * correctly print error --- src/sql/workbench/contrib/query/browser/queryActions.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/sql/workbench/contrib/query/browser/queryActions.ts b/src/sql/workbench/contrib/query/browser/queryActions.ts index d4eaf0fc78..28c25f99d9 100644 --- a/src/sql/workbench/contrib/query/browser/queryActions.ts +++ b/src/sql/workbench/contrib/query/browser/queryActions.ts @@ -44,7 +44,7 @@ import { ConnectionProfile } from 'sql/platform/connection/common/connectionProf import { IQueryManagementService } from 'sql/workbench/services/query/common/queryManagement'; import { ILogService } from 'vs/platform/log/common/log'; import { IRange } from 'vs/editor/common/core/range'; -import { onUnexpectedError } from 'vs/base/common/errors'; +import { getErrorMessage, onUnexpectedError } from 'vs/base/common/errors'; /** * Action class that query-based Actions will extend. This base class automatically handles activating and @@ -684,6 +684,11 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt // PRIVATE HELPERS ///////////////////////////////////////////////////// private databaseSelected(dbName: string): void { + // If dbName is blank (this can happen for example when setting the box value to empty when disconnecting) + // then just no-op, there's nothing we can do. + if (!dbName) { + return; + } if (!this._editor.input) { this.logService.error('editor input was null'); return; @@ -714,7 +719,7 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt this.resetDatabaseName(); this.notificationService.notify({ severity: Severity.Error, - message: nls.localize('changeDatabase.failedWithError', "Failed to change database {0}", error) + message: nls.localize('changeDatabase.failedWithError', "Failed to change database: {0}", getErrorMessage(error)) }); }); }