diff --git a/src/common/cluster/cluster.ts b/src/common/cluster/cluster.ts index f3723e140b..11b67bd002 100644 --- a/src/common/cluster/cluster.ts +++ b/src/common/cluster/cluster.ts @@ -340,15 +340,35 @@ export class Cluster implements ClusterModel, ClusterState { } if (this.disconnected || !this.accessible) { - await this.reconnect(); + try { + this.broadcastConnectUpdate("Starting connection ..."); + await this.reconnect(); + } catch (error) { + this.broadcastConnectUpdate(`Failed to start connection: ${error}`, true); + + return; + } } - this.broadcastConnectUpdate("Refreshing connection status ..."); - await this.refreshConnectionStatus(); + try { + this.broadcastConnectUpdate("Refreshing connection status ..."); + await this.refreshConnectionStatus(); + } catch (error) { + this.broadcastConnectUpdate(`Failed to connection status: ${error}`, true); + + return; + } if (this.accessible) { - this.broadcastConnectUpdate("Refreshing cluster accessibility ..."); - await this.refreshAccessibility(); + try { + this.broadcastConnectUpdate("Refreshing cluster accessibility ..."); + await this.refreshAccessibility(); + } catch (error) { + this.broadcastConnectUpdate(`Failed to refresh accessibility: ${error}`, true); + + return; + } + // download kubectl in background, so it's not blocking dashboard this.ensureKubectl() .catch(error => this.dependencies.logger.warn(`[CLUSTER]: failed to download kubectl for clusterId=${this.id}`, error)); diff --git a/src/common/logger.ts b/src/common/logger.ts index 7df4db08c7..fd9345d61e 100644 --- a/src/common/logger.ts +++ b/src/common/logger.ts @@ -78,4 +78,4 @@ export default winston.createLogger({ format.simple(), ), transports, -}); +}) as Logger; diff --git a/src/main/kube-auth-proxy/kube-auth-proxy.ts b/src/main/kube-auth-proxy/kube-auth-proxy.ts index 414ea334da..fbbfa67a85 100644 --- a/src/main/kube-auth-proxy/kube-auth-proxy.ts +++ b/src/main/kube-auth-proxy/kube-auth-proxy.ts @@ -16,7 +16,10 @@ import { TypedRegEx } from "typed-regex"; import type { Spawn } from "../child-process/spawn.injectable"; import type { Logger } from "../../common/logger"; -const startingServeRegex = TypedRegEx("starting to serve on (?
.+)", "i"); +const startingServeMatcher = "starting to serve on (?.+)"; +const startingServeRegex = Object.assign(TypedRegEx(startingServeMatcher, "i"), { + rawMatcher: startingServeMatcher, +}); export interface KubeAuthProxyDependencies { readonly proxyBinPath: string; diff --git a/src/main/kubectl/kubectl.ts b/src/main/kubectl/kubectl.ts index 55f7e4675d..6fde083de5 100644 --- a/src/main/kubectl/kubectl.ts +++ b/src/main/kubectl/kubectl.ts @@ -132,8 +132,7 @@ export class Kubectl { return this.path; } catch (err) { - logger.error("Failed to ensure kubectl, fallback to the bundled version"); - logger.error(err); + logger.error("Failed to ensure kubectl, fallback to the bundled version", err); return this.getBundledPath(); } @@ -146,7 +145,7 @@ export class Kubectl { return this.dirname; } catch (err) { - logger.error(err); + logger.error("Failed to get biniary directory", err); return ""; } diff --git a/src/main/routes/metrics/add-metrics-route.injectable.ts b/src/main/routes/metrics/add-metrics-route.injectable.ts index 8bd6ad2c72..b97a08d827 100644 --- a/src/main/routes/metrics/add-metrics-route.injectable.ts +++ b/src/main/routes/metrics/add-metrics-route.injectable.ts @@ -31,11 +31,11 @@ const loadMetricsFor = (getMetrics: GetMetrics) => async (promQueries: string[], } catch (error) { if (isRequestError(error)) { if (lastAttempt || (error.statusCode && error.statusCode >= 400 && error.statusCode < 500)) { - logger.error("[Metrics]: metrics not available", error?.response ? error.response?.body : error); - throw new Error("Metrics not available"); + throw new Error("Metrics not available", { cause: error }); } + } else if (error instanceof Error) { + throw new Error("Metrics not available", { cause: error }); } else { - logger.error("[Metrics]: metrics not available", error); throw new Error("Metrics not available"); } diff --git a/src/main/routes/port-forward/functionality/port-forward.ts b/src/main/routes/port-forward/functionality/port-forward.ts index eafe465972..43d8f9d425 100644 --- a/src/main/routes/port-forward/functionality/port-forward.ts +++ b/src/main/routes/port-forward/functionality/port-forward.ts @@ -9,7 +9,10 @@ import { spawn } from "child_process"; import * as tcpPortUsed from "tcp-port-used"; import { TypedRegEx } from "typed-regex"; -const internalPortRegex = TypedRegEx("^forwarding from (?.+) ->", "i"); +const internalPortMatcher = "^forwarding from (?.+) ->"; +const internalPortRegex = Object.assign(TypedRegEx(internalPortMatcher, "i"), { + rawMatcher: internalPortMatcher, +}); export interface PortForwardArgs { clusterId: string; diff --git a/src/main/utils/get-port.ts b/src/main/utils/get-port.ts index 6ce76f6795..b0d7f5615f 100644 --- a/src/main/utils/get-port.ts +++ b/src/main/utils/get-port.ts @@ -20,6 +20,7 @@ interface GetPortArgs { }; raw?: RegExpExecArray; }; + rawMatcher: string; }; /** * Called when the port is found @@ -27,7 +28,7 @@ interface GetPortArgs { onFind?: () => void; /** * Timeout for how long to wait for the port. - * Default: 5s + * Default: 15s */ timeout?: number; } @@ -61,7 +62,7 @@ export function getPortFrom(stream: Readable, args: GetPortArgs): Promise