From a50862266b9551fee2315be72db9d3163ab4ea98 Mon Sep 17 00:00:00 2001 From: Andre Dietisheim Date: Mon, 8 Sep 2025 11:04:20 +0200 Subject: [PATCH] move Throwable.rootMessage() to helper class Signed-off-by: Muthurajan Sivasubramanian Co-authored-by: Andre Dietisheim --- .../devtools/gateway/util/ExceptionUtils.kt | 22 +++++++++++++++++++ .../DevSpacesOpenShiftConnectionStepView.kt | 12 +--------- 2 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 src/main/kotlin/com/redhat/devtools/gateway/util/ExceptionUtils.kt diff --git a/src/main/kotlin/com/redhat/devtools/gateway/util/ExceptionUtils.kt b/src/main/kotlin/com/redhat/devtools/gateway/util/ExceptionUtils.kt new file mode 100644 index 0000000..f013f9d --- /dev/null +++ b/src/main/kotlin/com/redhat/devtools/gateway/util/ExceptionUtils.kt @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 Red Hat, Inc. + * This program and the accompanying materials are made + * available under the terms of the Eclipse Public License 2.0 + * which is available at https://www.eclipse.org/legal/epl-2.0/ + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * Red Hat, Inc. - initial API and implementation + */ +package com.redhat.devtools.gateway.util + +fun Throwable.rootMessage(): String { + var cause: Throwable? = this + while (cause?.cause != null) { + cause = cause.cause + } + return cause?.message?.trim() + ?: this.message?.substringAfter(":")?.trim() + ?: "Unknown error" +} diff --git a/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesOpenShiftConnectionStepView.kt b/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesOpenShiftConnectionStepView.kt index 25db62d..4d7a970 100644 --- a/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesOpenShiftConnectionStepView.kt +++ b/src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesOpenShiftConnectionStepView.kt @@ -28,6 +28,7 @@ import com.redhat.devtools.gateway.openshift.OpenShiftClientFactory import com.redhat.devtools.gateway.openshift.Projects import com.redhat.devtools.gateway.openshift.kube.KubeConfigBuilder import com.redhat.devtools.gateway.settings.DevSpacesSettings +import com.redhat.devtools.gateway.util.rootMessage import com.redhat.devtools.gateway.view.InformationDialog import com.redhat.devtools.gateway.view.ui.FilteringComboBox import com.redhat.devtools.gateway.view.ui.PasteClipboardMenu @@ -118,17 +119,6 @@ class DevSpacesOpenShiftConnectionStepView(private var devSpacesContext: DevSpac return success } - private fun Throwable.rootMessage(): String { - // Walk down to the root cause - var cause: Throwable? = this - while (cause?.cause != null) { - cause = cause.cause - } - return cause?.message?.trim() - ?: this.message?.substringAfter(":")?.trim() - ?: "Unknown error" - } - private fun loadOpenShiftConnectionSettings() { tfServer.removeAllItems() allServers.forEach { tfServer.addItem(it) }