Skip to content

Commit

Permalink
refactor(proxy): add friendly error messages for missing context or i…
Browse files Browse the repository at this point in the history
…nvalid cli flags
  • Loading branch information
monojack committed Feb 22, 2024
1 parent 1890b14 commit 8508bc1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions electron/app/services/cluster/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?',
Expand Down
6 changes: 6 additions & 0 deletions electron/app/services/cluster/handlers/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions electron/kubernetes/ProxyInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8508bc1

Please sign in to comment.