From 2219b8087f6b1e03a219a709a111b6dfb1433d9f Mon Sep 17 00:00:00 2001 From: Katsiaryna Tsytsenia Date: Tue, 5 Nov 2024 02:43:43 +0200 Subject: [PATCH] IJMP-1923 Fixed IDE error in case of invalid zowe.config --- .../ui/zosmf/ZOSMFConnectionConfigurable.kt | 9 ++++++++- .../zowe/actions/UpdateZoweConfigAction.kt | 18 ++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/org/zowe/explorer/config/connect/ui/zosmf/ZOSMFConnectionConfigurable.kt b/src/main/kotlin/org/zowe/explorer/config/connect/ui/zosmf/ZOSMFConnectionConfigurable.kt index 27d6d58b..cc962bac 100644 --- a/src/main/kotlin/org/zowe/explorer/config/connect/ui/zosmf/ZOSMFConnectionConfigurable.kt +++ b/src/main/kotlin/org/zowe/explorer/config/connect/ui/zosmf/ZOSMFConnectionConfigurable.kt @@ -14,6 +14,7 @@ package org.zowe.explorer.config.connect.ui.zosmf +import com.google.gson.JsonSyntaxException import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.runInEdt import com.intellij.openapi.options.BoundSearchableConfigurable @@ -34,6 +35,7 @@ import org.zowe.explorer.config.connect.Credentials import org.zowe.explorer.config.ws.FilesWorkingSetConfig import org.zowe.explorer.config.ws.JesWorkingSetConfig import org.zowe.explorer.config.ws.WorkingSetConfig +import org.zowe.explorer.telemetry.NotificationsService import org.zowe.explorer.utils.crudable.getAll import org.zowe.explorer.utils.isThe import org.zowe.explorer.utils.runWriteActionInEdtAndWait @@ -109,7 +111,12 @@ class ZOSMFConnectionConfigurable : BoundSearchableConfigurable("z/OSMF Connecti return } - val zoweConfig = parseConfigJson(configFile.inputStream) + val zoweConfig = try { + parseConfigJson(configFile.inputStream) + } catch (e: JsonSyntaxException) { + NotificationsService.getService().notifyError(Exception("Cannot parse Zowe config file")) + return + } zoweConfig.extractSecureProperties(configFile.path.split("/").toTypedArray()) kotlin.runCatching { zoweConfig.updateFromState(state) diff --git a/src/main/kotlin/org/zowe/explorer/zowe/actions/UpdateZoweConfigAction.kt b/src/main/kotlin/org/zowe/explorer/zowe/actions/UpdateZoweConfigAction.kt index 7ef55583..3cfc2b24 100644 --- a/src/main/kotlin/org/zowe/explorer/zowe/actions/UpdateZoweConfigAction.kt +++ b/src/main/kotlin/org/zowe/explorer/zowe/actions/UpdateZoweConfigAction.kt @@ -14,6 +14,7 @@ package org.zowe.explorer.zowe.actions +import com.google.gson.JsonSyntaxException import com.intellij.openapi.actionSystem.ActionUpdateThread import com.intellij.openapi.actionSystem.AnActionEvent import com.intellij.openapi.actionSystem.CommonDataKeys @@ -84,12 +85,17 @@ class UpdateZoweConfigAction : DumbAwareAction() { zoweConfigService.localZoweConfig else zoweConfigService.globalZoweConfig - if (type == ZoweConfigType.LOCAL) { - zoweConfigService.localZoweConfig = parseConfigJson(editor.document.text) - zoweConfigService.localZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray()) - } else { - zoweConfigService.globalZoweConfig = parseConfigJson(editor.document.text) - zoweConfigService.globalZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray()) + try { + if (type == ZoweConfigType.LOCAL) { + zoweConfigService.localZoweConfig = parseConfigJson(editor.document.text) + zoweConfigService.localZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray()) + } else { + zoweConfigService.globalZoweConfig = parseConfigJson(editor.document.text) + zoweConfigService.globalZoweConfig?.extractSecureProperties(vFile.path.split("/").toTypedArray()) + } + } catch (ex: JsonSyntaxException) { + e.presentation.isEnabledAndVisible = false + return } val zoweState = zoweConfigService.getZoweConfigState(false, type = type) e.presentation.isEnabledAndVisible =