From 8508bc12cb1674da0ea8eca322ae5dc179627e47 Mon Sep 17 00:00:00 2001 From: Ionut Achim Date: Thu, 22 Feb 2024 10:31:13 +0200 Subject: [PATCH] refactor(proxy): add friendly error messages for missing context or invalid cli flags --- electron/app/services/cluster/errors.ts | 8 ++++++++ electron/app/services/cluster/handlers/setup.ts | 6 ++++++ electron/kubernetes/ProxyInstance.ts | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/electron/app/services/cluster/errors.ts b/electron/app/services/cluster/errors.ts index edb2b16908..7109bc57b1 100644 --- a/electron/app/services/cluster/errors.ts +++ b/electron/app/services/cluster/errors.ts @@ -14,6 +14,14 @@ const errors = createErrors({ title: 'Cannot connect to the cluster', description: 'There is no current context selected.', }, + 'proxy-missing-context': { + title: 'Cannot connect to the cluster', + description: 'The specified context does not exist. Please check your kubeconfig file.', + }, + 'proxy-invalid-config': { + title: 'Cannot connect to the cluster', + description: 'The proxy connection arguments were invalid.', + }, 'local-connection-refused': { title: 'Cannot connect to the cluster', description: 'The connection was refused - is your Docker Engine or VM running?', diff --git a/electron/app/services/cluster/handlers/setup.ts b/electron/app/services/cluster/handlers/setup.ts index af1c0a84e6..b6a4c26cc3 100644 --- a/electron/app/services/cluster/handlers/setup.ts +++ b/electron/app/services/cluster/handlers/setup.ts @@ -48,6 +48,12 @@ function determineError(reason: string, contextId: ContextId): MonokleClusterErr if (reason === 'MONOKLE_PROXY_EMPTY_CONTEXT') { return getMonokleClusterError('proxy-empty-context', contextId); } + if (reason === 'MONOKLE_PROXY_MISSING_CONTEXT') { + return getMonokleClusterError('proxy-missing-context', contextId); + } + if (reason === 'MONOKLE_PROXY_INVALID_CONFIG') { + return getMonokleClusterError('proxy-invalid-config', contextId); + } // Kubectl user authentication error. // These happen within the local kube-proxy. diff --git a/electron/kubernetes/ProxyInstance.ts b/electron/kubernetes/ProxyInstance.ts index 9681ab28a4..08970bbc4c 100644 --- a/electron/kubernetes/ProxyInstance.ts +++ b/electron/kubernetes/ProxyInstance.ts @@ -113,6 +113,10 @@ export class ProxyInstance { proxySignal.reject(new Error('EADDRINUSE')); } else if (msg.includes('error: The gcp auth plugin has been removed')) { proxySignal.reject(new Error('MONOKLE_PROXY_GCP_LEGACY_PLUGIN')); + } else if (/^error: flags cannot be placed before/i.test(msg)) { + proxySignal.reject(new Error('MONOKLE_PROXY_INVALID_CONFIG')); + } else if (/^(error: context).*(does not exist)/i.test(msg)) { + proxySignal.reject(new Error('MONOKLE_PROXY_MISSING_CONTEXT')); } else { // do nothing and let the timeout reject eventually. // For instance, high verbosity logs plenty of details