From acb119af94bef437bffaff7aa70afe7d1ef76085 Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Fri, 20 May 2022 05:27:47 -0700 Subject: [PATCH] Fix error in legacyRegisterApi on main (#5426) --- src/common/k8s-api/kube-api.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/common/k8s-api/kube-api.ts b/src/common/k8s-api/kube-api.ts index f4435c9201..bc1c2f6415 100644 --- a/src/common/k8s-api/kube-api.ts +++ b/src/common/k8s-api/kube-api.ts @@ -312,12 +312,23 @@ export interface DeleteResourceDescriptor extends ResourceDescriptor { * @deprecated In the new extension API, don't expose `KubeApi`'s constructor */ function legacyRegisterApi(api: KubeApi): void { - const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.renderer); - - if (di) { + try { + /** + * This function throws if called in `main`, so the `try..catch` is to make sure that doesn't + * leak. + * + * However, we need this code to be run in `renderer` so that the auto registering of `KubeApi` + * instances still works. That auto registering never worked or was applicable in `main` because + * there is no "single cluster" on `main`. + * + * TODO: rearchitect this design pattern in the new extension API + */ + const di = getEnvironmentSpecificLegacyGlobalDiForExtensionApi(Environments.renderer); const autoRegistrationEmitter = di.inject(autoRegistrationEmitterInjectable); autoRegistrationEmitter.emit("kubeApi", api); + } catch { + // ignore error } }