diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2021-09-15 11:03:14 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2021-09-16 12:04:36 +0200 |
| commit | 4cea60889a5a5cd9cefc76df2afc2af612021e7e (patch) | |
| tree | bfbcbd8f3bc40842fa62ac019c7517a91278ec1e /gui/src | |
| parent | 4d9a8206dcfc5312160a8d0b7066157c8f2a71f4 (diff) | |
| download | mullvadvpn-4cea60889a5a5cd9cefc76df2afc2af612021e7e.tar.xz mullvadvpn-4cea60889a5a5cd9cefc76df2afc2af612021e7e.zip | |
Update catch-statements to work with unknown type
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/main/account-data-cache.ts | 3 | ||||
| -rw-r--r-- | gui/src/main/autostart.ts | 11 | ||||
| -rw-r--r-- | gui/src/main/daemon-rpc.ts | 14 | ||||
| -rw-r--r-- | gui/src/main/gui-settings.ts | 3 | ||||
| -rw-r--r-- | gui/src/main/index.ts | 63 | ||||
| -rw-r--r-- | gui/src/main/linux-desktop-entry.ts | 5 | ||||
| -rw-r--r-- | gui/src/main/linux-split-tunneling.ts | 3 | ||||
| -rw-r--r-- | gui/src/main/load-translations.ts | 6 | ||||
| -rw-r--r-- | gui/src/renderer/app.tsx | 18 | ||||
| -rw-r--r-- | gui/src/renderer/components/ClipboardLabel.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/containers/AdvancedSettingsPage.tsx | 9 | ||||
| -rw-r--r-- | gui/src/renderer/containers/ConnectPage.tsx | 9 | ||||
| -rw-r--r-- | gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx | 6 | ||||
| -rw-r--r-- | gui/src/renderer/containers/OpenVPNSettingsPage.tsx | 12 | ||||
| -rw-r--r-- | gui/src/renderer/containers/PreferencesPage.tsx | 3 | ||||
| -rw-r--r-- | gui/src/renderer/containers/SelectLocationPage.tsx | 9 | ||||
| -rw-r--r-- | gui/src/renderer/containers/WireguardSettingsPage.tsx | 6 | ||||
| -rw-r--r-- | gui/src/shared/ipc-helpers.ts | 3 | ||||
| -rw-r--r-- | gui/src/shared/logging.ts | 3 |
19 files changed, 125 insertions, 64 deletions
diff --git a/gui/src/main/account-data-cache.ts b/gui/src/main/account-data-cache.ts index d55b511feb..031ffb50bd 100644 --- a/gui/src/main/account-data-cache.ts +++ b/gui/src/main/account-data-cache.ts @@ -111,7 +111,8 @@ export default class AccountDataCache { this.waitStrategy.reset(); this.performingFetch = false; } - } catch (error) { + } catch (e) { + const error = e as Error; if (this.currentAccount === accountToken) { this.handleFetchError(accountToken, error); this.performingFetch = false; diff --git a/gui/src/main/autostart.ts b/gui/src/main/autostart.ts index 8c77ba3b6a..d5fdf39685 100644 --- a/gui/src/main/autostart.ts +++ b/gui/src/main/autostart.ts @@ -15,7 +15,8 @@ export function getOpenAtLogin() { fs.accessSync(autostartFilePath); return true; - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to check autostart file: ${error.message}`); return false; } @@ -37,7 +38,8 @@ export async function setOpenAtLogin(openAtLogin: boolean) { } else { await fs.promises.unlink(autostartFilePath); } - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to set auto-start: ${error.message}`); } } else { @@ -59,7 +61,7 @@ const createDirIfNecessary = async (directory: string) => { let stat; try { stat = await fs.promises.stat(directory); - } catch (error) { + } catch { // Path doesn't exist, so it has to be created return fs.promises.mkdir(directory); } @@ -69,7 +71,8 @@ const createDirIfNecessary = async (directory: string) => { // Try to remove existing file and replace it with a new directory try { await fs.promises.unlink(directory); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to remove path before creating a directory for it: ${error.message}`); } diff --git a/gui/src/main/daemon-rpc.ts b/gui/src/main/daemon-rpc.ts index 7464e0b5c9..0619e873ca 100644 --- a/gui/src/main/daemon-rpc.ts +++ b/gui/src/main/daemon-rpc.ts @@ -183,7 +183,8 @@ export class DaemonRpc { ); const expiry = response.getExpiry()!.toDate().toISOString(); return { expiry }; - } catch (error) { + } catch (e) { + const error = e as grpc.ServiceError; if (error.code) { switch (error.code) { case grpc.status.UNAUTHENTICATED: @@ -223,7 +224,8 @@ export class DaemonRpc { secondsAdded, newExpiry, }; - } catch (error) { + } catch (e) { + const error = e as grpc.ServiceError; if (error.code) { switch (error.code) { case grpc.status.NOT_FOUND: @@ -405,8 +407,9 @@ export class DaemonRpc { try { const daemonEvent = convertFromDaemonEvent(data); listener.onEvent(daemonEvent); - } catch (err) { - listener.onError(err); + } catch (e) { + const error = e as Error; + listener.onError(error); } }); @@ -557,7 +560,8 @@ export class DaemonRpc { subscription.removeAllListeners('error'); try { subscription.cancel(); - } catch (error) { + } catch (e) { + const error = e as grpc.ServiceError; if (error.code !== grpc.status.CANCELLED) { throw error; } diff --git a/gui/src/main/gui-settings.ts b/gui/src/main/gui-settings.ts index 57dc754cd8..940dd7215c 100644 --- a/gui/src/main/gui-settings.ts +++ b/gui/src/main/gui-settings.ts @@ -102,7 +102,8 @@ export default class GuiSettings { ...defaultSettings, ...this.validateSettings(rawJson), }; - } catch (error) { + } catch (e) { + const error = e as Error & { code?: string }; // Read settings if the file exists, otherwise write the default settings to it. if (error.code === 'ENOENT') { log.debug('Creating gui-settings file and writing the default settings to it'); diff --git a/gui/src/main/index.ts b/gui/src/main/index.ts index 34aa60ce6d..3421e72894 100644 --- a/gui/src/main/index.ts +++ b/gui/src/main/index.ts @@ -334,7 +334,8 @@ class ApplicationMain { log.addOutput(new FileOutput(LogLevel.debug, mainLogPath)); this.rendererLog.addOutput(new FileOutput(LogLevel.debug, rendererLogPath)); } catch (e) { - console.error('Failed to initialize logging:', e); + const error = e as Error; + console.error('Failed to initialize logging:', error); } } @@ -378,7 +379,8 @@ class ApplicationMain { await this.daemonRpc.disconnectTunnel(); log.info('Disconnected the tunnel'); } catch (e) { - log.error(`Failed to disconnect the tunnel: ${e.message}`); + const error = e as Error; + log.error(`Failed to disconnect the tunnel: ${error.message}`); } } else { log.info('Cannot close the tunnel because there is no active connection to daemon.'); @@ -392,7 +394,8 @@ class ApplicationMain { log.info('Unsubscribed from the daemon events'); } } catch (e) { - log.error(`Failed to unsubscribe from daemon events: ${e.message}`); + const error = e as Error; + log.error(`Failed to unsubscribe from daemon events: ${error.message}`); } // The window is not closable on macOS to be able to hide the titlebar and workaround @@ -410,7 +413,8 @@ class ApplicationMain { try { logger?.dispose(); } catch (e) { - console.error('Failed to dispose logger:', e); + const error = e as Error; + console.error('Failed to dispose logger:', error); } } } @@ -522,7 +526,8 @@ class ApplicationMain { const filePath = path.resolve(path.join(__dirname, '../renderer/index.html')); try { await this.windowController.window.loadFile(filePath); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to load index file: ${error.message}`); } @@ -543,7 +548,8 @@ class ApplicationMain { // subscribe to events try { this.daemonEventListener = this.subscribeEvents(); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to subscribe: ${error.message}`); return this.recoverFromBootstrapError(error); @@ -552,7 +558,8 @@ class ApplicationMain { // fetch account history try { this.setAccountHistory(await this.daemonRpc.getAccountHistory()); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to fetch the account history: ${error.message}`); return this.recoverFromBootstrapError(error); @@ -561,7 +568,8 @@ class ApplicationMain { // fetch the tunnel state try { this.setTunnelState(await this.daemonRpc.getState()); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to fetch the tunnel state: ${error.message}`); return this.recoverFromBootstrapError(error); @@ -570,7 +578,8 @@ class ApplicationMain { // fetch settings try { this.setSettings(await this.daemonRpc.getSettings()); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to fetch settings: ${error.message}`); return this.recoverFromBootstrapError(error); @@ -587,7 +596,8 @@ class ApplicationMain { this.settings.relaySettings, this.settings.bridgeState, ); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to fetch relay locations: ${error.message}`); return this.recoverFromBootstrapError(error); @@ -596,7 +606,8 @@ class ApplicationMain { // fetch the daemon's version try { this.setDaemonVersion(await this.daemonRpc.getCurrentVersion()); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to fetch the daemon's version: ${error.message}`); return this.recoverFromBootstrapError(error); @@ -1005,7 +1016,8 @@ class ApplicationMain { private async fetchLatestVersion() { try { this.setLatestVersion(await this.daemonRpc.getVersionInfo()); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to request the version info: ${error.message}`); } } @@ -1354,7 +1366,8 @@ class ApplicationMain { private async createNewAccount(): Promise<string> { try { return await this.daemonRpc.createNewAccount(); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to create account: ${error.message}`); throw error; } @@ -1378,7 +1391,8 @@ class ApplicationMain { AUTO_CONNECT_FALLBACK_DELAY, ); } - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to login: ${error.message}`); this.autoConnectOnWireguardKeyEvent = false; @@ -1411,7 +1425,8 @@ class ApplicationMain { log.info('Autoconnect the tunnel'); await this.daemonRpc.connectTunnel(); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to autoconnect the tunnel: ${error.message}`); } } else { @@ -1428,7 +1443,8 @@ class ApplicationMain { this.autoConnectFallbackScheduler.cancel(); this.accountExpiryNotificationScheduler.cancel(); - } catch (error) { + } catch (e) { + const error = e as Error; log.info(`Failed to logout: ${error.message}`); throw error; @@ -1508,7 +1524,8 @@ class ApplicationMain { private async updateAccountHistory(): Promise<void> { try { this.setAccountHistory(await this.daemonRpc.getAccountHistory()); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to fetch the account history: ${error.message}`); } } @@ -1516,7 +1533,8 @@ class ApplicationMain { private async fetchWireguardKey(): Promise<void> { try { this.setWireguardKey(await this.daemonRpc.getWireguardKey()); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to fetch wireguard key: ${error.message}`); } } @@ -1537,7 +1555,8 @@ class ApplicationMain { } this.updateDaemonsAutoConnect(); - } catch (error) { + } catch (e) { + const error = e as Error; log.error( `Failed to update the autostart to ${autoStart.toString()}. ${error.message.toString()}`, ); @@ -1647,7 +1666,8 @@ class ApplicationMain { await installer(REACT_DEVELOPER_TOOLS, options); await installer(REDUX_DEVTOOLS, options); } catch (e) { - log.info(`Error installing extension: ${e.message}`); + const error = e as Error; + log.info(`Error installing extension: ${error.message}`); } } @@ -1998,7 +2018,8 @@ class ApplicationMain { try { token = await this.daemonRpc.getWwwAuthToken(); } catch (e) { - log.error(`Failed to get the WWW auth token: ${e.message}`); + const error = e as Error; + log.error(`Failed to get the WWW auth token: ${error.message}`); } return shell.openExternal(`${url}?token=${token}`); } else { diff --git a/gui/src/main/linux-desktop-entry.ts b/gui/src/main/linux-desktop-entry.ts index 291079aea8..52ea526022 100644 --- a/gui/src/main/linux-desktop-entry.ts +++ b/gui/src/main/linux-desktop-entry.ts @@ -149,7 +149,7 @@ async function getDesktopEntriesInDirectory( ); } } - } catch (e) { + } catch { // no-op } @@ -289,7 +289,8 @@ async function findIcon( let contents: string[] | undefined; try { contents = await fs.promises.readdir(directory); - } catch (error) { + } catch (e) { + const error = e as NodeJS.ErrnoException; // Non-existent directories and files (not a directory) are expected. if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') { log.error(`Failed to open directory while searching for ${name} icon`, error); diff --git a/gui/src/main/linux-split-tunneling.ts b/gui/src/main/linux-split-tunneling.ts index 9c41740776..17f24619f4 100644 --- a/gui/src/main/linux-split-tunneling.ts +++ b/gui/src/main/linux-split-tunneling.ts @@ -37,7 +37,8 @@ export async function launchApplication( try { excludeArguments = await getLaunchCommand(app); } catch (e) { - return { error: e.message }; + const error = e as Error; + return { error: error.message }; } return new Promise((resolve, _reject) => { diff --git a/gui/src/main/load-translations.ts b/gui/src/main/load-translations.ts index 63d76f0ac6..cb597e484d 100644 --- a/gui/src/main/load-translations.ts +++ b/gui/src/main/load-translations.ts @@ -51,7 +51,8 @@ function parseTranslation( try { contents = fs.readFileSync(filename, { encoding: 'utf8' }); - } catch (error) { + } catch (e) { + const error = e as NodeJS.ErrnoException; if (error.code !== 'ENOENT') { log.error(`Cannot read the gettext file "${filename}": ${error.message}`); } @@ -61,7 +62,8 @@ function parseTranslation( let translations: GetTextTranslations; try { translations = po.parse(contents); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Cannot parse the gettext file "${filename}": ${error.message}`); return undefined; } diff --git a/gui/src/renderer/app.tsx b/gui/src/renderer/app.tsx index c888480033..296638b205 100644 --- a/gui/src/renderer/app.tsx +++ b/gui/src/renderer/app.tsx @@ -297,7 +297,8 @@ export default class AppRenderer { actions.account.updateAccountToken(accountToken); actions.account.loggedIn(); this.redirectToConnect(); - } catch (error) { + } catch (e) { + const error = e as Error; actions.account.loginFailed(error); } } @@ -306,7 +307,8 @@ export default class AppRenderer { try { await IpcRendererEventChannel.account.logout(); } catch (e) { - log.info('Failed to logout: ', e.message); + const error = e as Error; + log.info('Failed to logout: ', error.message); } } @@ -322,7 +324,8 @@ export default class AppRenderer { const accountExpiry = new Date().toISOString(); actions.account.accountCreated(accountToken, accountExpiry); this.redirectToConnect(); - } catch (error) { + } catch (e) { + const error = e as Error; actions.account.createAccountFailed(error); } } @@ -404,7 +407,8 @@ export default class AppRenderer { try { token = await IpcRendererEventChannel.account.getWwwAuthToken(); } catch (e) { - log.error(`Failed to get the WWW auth token: ${e.message}`); + const error = e as Error; + log.error(`Failed to get the WWW auth token: ${error.message}`); } void this.openUrl(`${link}?token=${token}`); }; @@ -483,7 +487,8 @@ export default class AppRenderer { try { const valid = await IpcRendererEventChannel.wireguardKeys.verifyKey(); actions.settings.completeWireguardKeyVerification(valid); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to verify WireGuard key - ${error.message}`); actions.settings.completeWireguardKeyVerification(undefined); } @@ -981,7 +986,8 @@ export default class AppRenderer { if (location && getLocationPromise === this.getLocationPromise) { return location; } - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to update the location: ${error.message}`); } } diff --git a/gui/src/renderer/components/ClipboardLabel.tsx b/gui/src/renderer/components/ClipboardLabel.tsx index 2131e884df..43b0d2c764 100644 --- a/gui/src/renderer/components/ClipboardLabel.tsx +++ b/gui/src/renderer/components/ClipboardLabel.tsx @@ -50,7 +50,8 @@ export default class ClipboardLabel extends React.Component<IProps, IState> { await navigator.clipboard.writeText(this.props.value); this.scheduler.schedule(() => this.setState({ showsMessage: false }), this.props.delay); this.setState({ showsMessage: true }); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to copy to clipboard: ${error.message}`); } }; diff --git a/gui/src/renderer/containers/AdvancedSettingsPage.tsx b/gui/src/renderer/containers/AdvancedSettingsPage.tsx index 8e8acf2ee9..51ba310aad 100644 --- a/gui/src/renderer/containers/AdvancedSettingsPage.tsx +++ b/gui/src/renderer/containers/AdvancedSettingsPage.tsx @@ -53,7 +53,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.updateRelaySettings(relayUpdate); } catch (e) { - log.error('Failed to update tunnel protocol constraints', e.message); + const error = e as Error; + log.error('Failed to update tunnel protocol constraints', error.message); } }, @@ -61,7 +62,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.setEnableIpv6(enableIpv6); } catch (e) { - log.error('Failed to update enable IPv6', e.message); + const error = e as Error; + log.error('Failed to update enable IPv6', error.message); } }, @@ -69,7 +71,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.setBlockWhenDisconnected(blockWhenDisconnected); } catch (e) { - log.error('Failed to update block when disconnected', e.message); + const error = e as Error; + log.error('Failed to update block when disconnected', error.message); } }, diff --git a/gui/src/renderer/containers/ConnectPage.tsx b/gui/src/renderer/containers/ConnectPage.tsx index 2069b4012b..c9ae60897b 100644 --- a/gui/src/renderer/containers/ConnectPage.tsx +++ b/gui/src/renderer/containers/ConnectPage.tsx @@ -80,21 +80,24 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp onConnect: async () => { try { await props.app.connectTunnel(); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to connect the tunnel: ${error.message}`); } }, onDisconnect: async () => { try { await props.app.disconnectTunnel(); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to disconnect the tunnel: ${error.message}`); } }, onReconnect: async () => { try { await props.app.reconnectTunnel(); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to reconnect the tunnel: ${error.message}`); } }, diff --git a/gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx b/gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx index e5c56e7f28..dc5b12a40e 100644 --- a/gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx +++ b/gui/src/renderer/containers/ExpiredAccountErrorViewContainer.tsx @@ -20,7 +20,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp onDisconnect: async () => { try { await props.app.disconnectTunnel(); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Failed to disconnect the tunnel: ${error.message}`); } }, @@ -28,7 +29,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.setBlockWhenDisconnected(blockWhenDisconnected); } catch (e) { - log.error('Failed to update block when disconnected', e.message); + const error = e as Error; + log.error('Failed to update block when disconnected', error.message); } }, navigateToRedeemVoucher: () => { diff --git a/gui/src/renderer/containers/OpenVPNSettingsPage.tsx b/gui/src/renderer/containers/OpenVPNSettingsPage.tsx index 378dc9bb82..9212ca68ac 100644 --- a/gui/src/renderer/containers/OpenVPNSettingsPage.tsx +++ b/gui/src/renderer/containers/OpenVPNSettingsPage.tsx @@ -67,7 +67,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.updateRelaySettings(relayUpdate); } catch (e) { - log.error('Failed to update relay settings', e.message); + const error = e as Error; + log.error('Failed to update relay settings', error.message); } }, @@ -84,7 +85,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.updateRelaySettings(relayUpdate); } catch (e) { - log.error('Failed to update relay settings', e.message); + const error = e as Error; + log.error('Failed to update relay settings', error.message); } }, @@ -92,7 +94,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.setBridgeState(bridgeState); } catch (e) { - log.error(`Failed to update bridge state: ${e.message}`); + const error = e as Error; + log.error(`Failed to update bridge state: ${error.message}`); } }, @@ -100,7 +103,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.setOpenVpnMssfix(mssfix); } catch (e) { - log.error('Failed to update mssfix value', e.message); + const error = e as Error; + log.error('Failed to update mssfix value', error.message); } }, }; diff --git a/gui/src/renderer/containers/PreferencesPage.tsx b/gui/src/renderer/containers/PreferencesPage.tsx index a050afedf7..d4176d1ca2 100644 --- a/gui/src/renderer/containers/PreferencesPage.tsx +++ b/gui/src/renderer/containers/PreferencesPage.tsx @@ -30,7 +30,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp setAutoStart: async (autoStart: boolean) => { try { await props.app.setAutoStart(autoStart); - } catch (error) { + } catch (e) { + const error = e as Error; log.error(`Cannot set auto-start: ${error.message}`); } }, diff --git a/gui/src/renderer/containers/SelectLocationPage.tsx b/gui/src/renderer/containers/SelectLocationPage.tsx index ea931c8ea9..cd455a01f6 100644 --- a/gui/src/renderer/containers/SelectLocationPage.tsx +++ b/gui/src/renderer/containers/SelectLocationPage.tsx @@ -65,7 +65,8 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IHistoryProps & IApp await props.app.updateRelaySettings(relayUpdate); await props.app.connectTunnel(); } catch (e) { - log.error(`Failed to select the exit location: ${e.message}`); + const error = e as Error; + log.error(`Failed to select the exit location: ${error.message}`); } }, onSelectBridgeLocation: async (bridgeLocation: RelayLocation) => { @@ -77,7 +78,8 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IHistoryProps & IApp new BridgeSettingsBuilder().location.fromRaw(bridgeLocation).build(), ); } catch (e) { - log.error(`Failed to select the bridge location: ${e.message}`); + const error = e as Error; + log.error(`Failed to select the bridge location: ${error.message}`); } }, onSelectClosestToExit: async () => { @@ -87,7 +89,8 @@ const mapDispatchToProps = (dispatch: ReduxDispatch, props: IHistoryProps & IApp try { await props.app.updateBridgeSettings(new BridgeSettingsBuilder().location.any().build()); } catch (e) { - log.error(`Failed to set the bridge location to closest to exit: ${e.message}`); + const error = e as Error; + log.error(`Failed to set the bridge location to closest to exit: ${error.message}`); } }, onClearProviders: async () => { diff --git a/gui/src/renderer/containers/WireguardSettingsPage.tsx b/gui/src/renderer/containers/WireguardSettingsPage.tsx index cf7833d116..5e6c27105e 100644 --- a/gui/src/renderer/containers/WireguardSettingsPage.tsx +++ b/gui/src/renderer/containers/WireguardSettingsPage.tsx @@ -65,7 +65,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.updateRelaySettings(relayUpdate); } catch (e) { - log.error('Failed to update relay settings', e.message); + const error = e as Error; + log.error('Failed to update relay settings', error.message); } }, @@ -73,7 +74,8 @@ const mapDispatchToProps = (_dispatch: ReduxDispatch, props: IHistoryProps & IAp try { await props.app.setWireguardMtu(mtu); } catch (e) { - log.error('Failed to update mtu value', e.message); + const error = e as Error; + log.error('Failed to update mtu value', error.message); } }, diff --git a/gui/src/shared/ipc-helpers.ts b/gui/src/shared/ipc-helpers.ts index 8c3c851a80..31469ce88a 100644 --- a/gui/src/shared/ipc-helpers.ts +++ b/gui/src/shared/ipc-helpers.ts @@ -180,7 +180,8 @@ function handle<T, R>(event: string, ipcMain: EIpcMain): Handler<T, Promise<R>> ipcMain.handle(event, async (_ipcEvent, arg: T) => { try { return { type: 'success', value: await fn(arg) }; - } catch (error) { + } catch (e) { + const error = e as Error; return { type: 'error', message: error.message || '' }; } }); diff --git a/gui/src/shared/logging.ts b/gui/src/shared/logging.ts index d87778bf13..bfde85a9da 100644 --- a/gui/src/shared/logging.ts +++ b/gui/src/shared/logging.ts @@ -56,8 +56,9 @@ export class Logger { try { await maybePromise; } catch (e) { + const error = e as Error; console.error( - `${output.constructor.name}.write: ${e.message}. Original message: ${message}`, + `${output.constructor.name}.write: ${error.message}. Original message: ${message}`, ); } } |
