Skip to content

Commit a508622

Browse files
committed
move Throwable.rootMessage() to helper class
Signed-off-by: Muthurajan Sivasubramanian <[email protected]> Co-authored-by: Andre Dietisheim <[email protected]>
1 parent dc71c7b commit a508622

File tree

2 files changed

+23
-11
lines changed

2 files changed

+23
-11
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2025 Red Hat, Inc.
3+
* This program and the accompanying materials are made
4+
* available under the terms of the Eclipse Public License 2.0
5+
* which is available at https://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*
9+
* Contributors:
10+
* Red Hat, Inc. - initial API and implementation
11+
*/
12+
package com.redhat.devtools.gateway.util
13+
14+
fun Throwable.rootMessage(): String {
15+
var cause: Throwable? = this
16+
while (cause?.cause != null) {
17+
cause = cause.cause
18+
}
19+
return cause?.message?.trim()
20+
?: this.message?.substringAfter(":")?.trim()
21+
?: "Unknown error"
22+
}

src/main/kotlin/com/redhat/devtools/gateway/view/steps/DevSpacesOpenShiftConnectionStepView.kt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.redhat.devtools.gateway.openshift.OpenShiftClientFactory
2828
import com.redhat.devtools.gateway.openshift.Projects
2929
import com.redhat.devtools.gateway.openshift.kube.KubeConfigBuilder
3030
import com.redhat.devtools.gateway.settings.DevSpacesSettings
31+
import com.redhat.devtools.gateway.util.rootMessage
3132
import com.redhat.devtools.gateway.view.InformationDialog
3233
import com.redhat.devtools.gateway.view.ui.FilteringComboBox
3334
import com.redhat.devtools.gateway.view.ui.PasteClipboardMenu
@@ -118,17 +119,6 @@ class DevSpacesOpenShiftConnectionStepView(private var devSpacesContext: DevSpac
118119
return success
119120
}
120121

121-
private fun Throwable.rootMessage(): String {
122-
// Walk down to the root cause
123-
var cause: Throwable? = this
124-
while (cause?.cause != null) {
125-
cause = cause.cause
126-
}
127-
return cause?.message?.trim()
128-
?: this.message?.substringAfter(":")?.trim()
129-
?: "Unknown error"
130-
}
131-
132122
private fun loadOpenShiftConnectionSettings() {
133123
tfServer.removeAllItems()
134124
allServers.forEach { tfServer.addItem(it) }

0 commit comments

Comments
 (0)