Skip to content

Commit fe356a5

Browse files
committed
show error details when fetching children fails (#28)
Signed-off-by: Andre Dietisheim <[email protected]>
1 parent 8354bc8 commit fe356a5

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

src/main/kotlin/com/redhat/devtools/intellij/kubernetes/tree/TreeStructure.kt

+29-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import com.redhat.devtools.intellij.kubernetes.model.util.hasDeletionTimestamp
3030
import com.redhat.devtools.intellij.kubernetes.model.util.isSameResource
3131
import com.redhat.devtools.intellij.kubernetes.model.util.isWillBeDeleted
3232
import io.fabric8.kubernetes.api.model.HasMetadata
33+
import org.bouncycastle.asn1.x509.CRLReason.unspecified
3334
import javax.swing.Icon
3435

3536
/**
@@ -248,9 +249,36 @@ open class TreeStructure(
248249
project
249250
) {
250251
override fun getLabel(element: java.lang.Exception): String {
251-
return "Error: ${element.message ?: "unspecified"}"
252+
return "Error: ${getMessage(element)}"
252253
}
253254

255+
private fun getMessage(e: Exception): String {
256+
val causeMessage = e.cause?.message
257+
return if (causeMessage == null) {
258+
getMessageOrDefault(e)
259+
} else if (causeMessage.contains("Operation: ")) {
260+
/**
261+
* ex. minikube: KubernetesClientException:
262+
* "Operation: [list] for kind: [Service] with name: [null] in namespace: [default] failed."
263+
*/
264+
return e.cause?.cause?.message
265+
?: getMessageOrDefault(e)
266+
} else {
267+
/**
268+
* ex. OpenShift: KubernetesClientException:
269+
* "Failure executing: GET at: https://api.sandbox-m3.1530.p1.openshiftapps.com:6443/apis/project.openshift.io/v1/projects.
270+
* Message: Unauthorized! Token may have expired! Please log-in again. Unauthorized."
271+
*/
272+
causeMessage.substringAfter("Message: ", causeMessage)
273+
}
274+
}
275+
276+
private fun getMessageOrDefault(e: Exception): String {
277+
return e.message
278+
?: "unspecified"
279+
}
280+
281+
254282
override fun getIcon(element: java.lang.Exception): Icon {
255283
return AllIcons.General.BalloonError
256284
}

0 commit comments

Comments
 (0)