From 555f8fbb1e45dead135e18572c943cd0c972d571 Mon Sep 17 00:00:00 2001 From: Aasim Khan Date: Mon, 27 Feb 2023 23:46:14 -0800 Subject: [PATCH] Adding null checks to prevent runtime exceptions (#22054) --- .../connection/common/connectionConfig.ts | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/sql/platform/connection/common/connectionConfig.ts b/src/sql/platform/connection/common/connectionConfig.ts index 26820aa57d..4ad1e43f2d 100644 --- a/src/sql/platform/connection/common/connectionConfig.ts +++ b/src/sql/platform/connection/common/connectionConfig.ts @@ -269,18 +269,25 @@ export class ConnectionConfig { subgroups.push(group); // Get all connections in the settings let profiles = this.configurationService.inspect(CONNECTIONS_CONFIG_KEY).userValue; - // Remove the profiles from the connections - profiles = profiles!.filter(value => { - let providerConnectionProfile = ConnectionProfile.createFromStoredProfile(value, this._capabilitiesService); - return !connections.some((val) => val.getOptionsKey() === providerConnectionProfile.getOptionsKey()); - }); + + if (profiles) { + // Remove the profiles from the connections + profiles = profiles!.filter(value => { + let providerConnectionProfile = ConnectionProfile.createFromStoredProfile(value, this._capabilitiesService); + return !connections.some((val) => val.getOptionsKey() === providerConnectionProfile.getOptionsKey()); + }); + } // Get all groups in the settings let groups = this.configurationService.inspect(GROUPS_CONFIG_KEY).userValue; - // Remove subgroups in the settings - groups = groups!.filter((grp) => { - return !subgroups.some((item) => item.id === grp.id); - }); + + if (groups) { + // Remove subgroups in the settings + groups = groups!.filter((grp) => { + return !subgroups.some((item) => item.id === grp.id); + }); + } + return Promise.all([ this.configurationService.updateValue(CONNECTIONS_CONFIG_KEY, profiles, ConfigurationTarget.USER), this.configurationService.updateValue(GROUPS_CONFIG_KEY, groups, ConfigurationTarget.USER)