From 3b153106990929214d31e53e86a9c68a8bed9d48 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Fri, 4 Oct 2024 12:18:20 +0200 Subject: [PATCH] fix(proxy): show friendly error when proxy config is not supported COMPASS-8345 (#6321) * chore: show friendly error when proxy config is not supported * chore: fix log * chore: fix eslint checks --- packages/compass/src/main/application.ts | 37 +++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/packages/compass/src/main/application.ts b/packages/compass/src/main/application.ts index bc1297caf85..37207a21ced 100644 --- a/packages/compass/src/main/application.ts +++ b/packages/compass/src/main/application.ts @@ -2,6 +2,7 @@ import './disable-node-deprecations'; // Separate module so it runs first import path from 'path'; import { EventEmitter } from 'events'; import type { BrowserWindow, Event, ProxyConfig } from 'electron'; +import { dialog } from 'electron'; import { app, safeStorage, session } from 'electron'; import { ipcMain } from 'hadron-ipc'; import type { AutoUpdateManagerState } from './auto-update-manager'; @@ -301,7 +302,41 @@ class CompassApplication { try { const proxyOptions = proxyPreferenceToProxyOptions(value); await app.whenReady(); - await target.setProxy(translateToElectronProxyConfig(proxyOptions)); + + try { + const electronProxyConfig = + translateToElectronProxyConfig(proxyOptions); + await target.setProxy(electronProxyConfig); + } catch (err) { + const headline = String( + err && typeof err === 'object' && 'message' in err + ? err.message + : err || + 'Currently Compass does not support authenticated or ssh proxies.' + ); + + log.warn( + mongoLogId(1_001_000_332), + logContext, + 'Unable to set proxy configuration', + { + error: headline, + } + ); + + const sep = path.sep; + const configPath = `${app.getPath( + 'userData' + )}${sep}AppPreferences${sep}General.json`; + + dialog.showErrorBox( + 'Unsupported proxy configuration', + `${headline}\n\n + To reset the proxy configuration, remove the "proxy" key in ${configPath} and restart Compass.` + ); + + app.quit(); + } const agent = createAgent(proxyOptions); const fetch = createFetch(agent || {});