diff --git a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt index d853c12f1..9eddc46f2 100644 --- a/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt +++ b/src/main/kotlin/com/redhat/devtools/intellij/kubernetes/model/AllContexts.kt @@ -33,6 +33,7 @@ import io.fabric8.kubernetes.client.Config import io.fabric8.kubernetes.client.KubernetesClient import io.fabric8.kubernetes.client.KubernetesClientException import java.nio.file.Paths +import java.util.concurrent.CompletionException interface IAllContexts { /** @@ -137,19 +138,21 @@ open class AllContexts( newClient: ClientAdapter, toWatch: Collection>?, ) : IActiveContext? { - synchronized(this) { - replaceClient( - newClient, - this.client.get() - ) - this.current?.close() - newClient.config.save().join() - all.clear() // causes reload of all contexts when accessed afterwards - val newCurrent = this.current // gets new current from all - if (toWatch != null) { - newCurrent?.watchAll(toWatch) + try { + synchronized(this) { + replaceClient(newClient, this.client.get()) + newClient.config.save().join() + current?.close() + all.clear() // causes reload of all contexts when accessed afterwards + val newCurrent = current // gets new current from all + if (toWatch != null) { + newCurrent?.watchAll(toWatch) + } + return newCurrent } - return newCurrent + } catch (e: CompletionException) { + val cause = e.cause ?: throw e + throw cause } }