From 7a43836fd4c49272620ccb6d78c62bf2a84606d1 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Thu, 3 Oct 2024 16:03:30 +0200 Subject: [PATCH 1/3] chore: show friendly error when proxy config is not supported --- packages/compass/src/main/application.ts | 38 ++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/packages/compass/src/main/application.ts b/packages/compass/src/main/application.ts index bc1297caf85..3e34d63886b 100644 --- a/packages/compass/src/main/application.ts +++ b/packages/compass/src/main/application.ts @@ -1,7 +1,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 { BrowserWindow, Event, ProxyConfig, dialog } from 'electron'; import { app, safeStorage, session } from 'electron'; import { ipcMain } from 'hadron-ipc'; import type { AutoUpdateManagerState } from './auto-update-manager'; @@ -301,7 +301,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_328), + 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 || {}); From 67781f83901c5b793fef45b8c926059216193226 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Thu, 3 Oct 2024 16:24:03 +0200 Subject: [PATCH 2/3] chore: fix log --- packages/compass/src/main/application.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/compass/src/main/application.ts b/packages/compass/src/main/application.ts index 3e34d63886b..f88e2f519fb 100644 --- a/packages/compass/src/main/application.ts +++ b/packages/compass/src/main/application.ts @@ -315,7 +315,7 @@ class CompassApplication { ); log.warn( - mongoLogId(1_001_000_328), + mongoLogId(1_001_000_332), logContext, 'Unable to set proxy configuration', { From f308369262de23e1babd991a06bdfb283ec18a22 Mon Sep 17 00:00:00 2001 From: Kevin Mas Ruiz Date: Thu, 3 Oct 2024 16:49:34 +0200 Subject: [PATCH 3/3] chore: fix eslint checks --- packages/compass/src/main/application.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/compass/src/main/application.ts b/packages/compass/src/main/application.ts index f88e2f519fb..37207a21ced 100644 --- a/packages/compass/src/main/application.ts +++ b/packages/compass/src/main/application.ts @@ -1,7 +1,8 @@ import './disable-node-deprecations'; // Separate module so it runs first import path from 'path'; import { EventEmitter } from 'events'; -import { BrowserWindow, Event, ProxyConfig, dialog } from 'electron'; +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';