summaryrefslogtreecommitdiffhomepage
path: root/gui/src/main
diff options
context:
space:
mode:
authorOskar Nyberg <oskar@mullvad.net>2021-09-15 11:03:14 +0200
committerOskar Nyberg <oskar@mullvad.net>2021-09-16 12:04:36 +0200
commit4cea60889a5a5cd9cefc76df2afc2af612021e7e (patch)
treebfbcbd8f3bc40842fa62ac019c7517a91278ec1e /gui/src/main
parent4d9a8206dcfc5312160a8d0b7066157c8f2a71f4 (diff)
downloadmullvadvpn-4cea60889a5a5cd9cefc76df2afc2af612021e7e.tar.xz
mullvadvpn-4cea60889a5a5cd9cefc76df2afc2af612021e7e.zip
Update catch-statements to work with unknown type
Diffstat (limited to 'gui/src/main')
-rw-r--r--gui/src/main/account-data-cache.ts3
-rw-r--r--gui/src/main/autostart.ts11
-rw-r--r--gui/src/main/daemon-rpc.ts14
-rw-r--r--gui/src/main/gui-settings.ts3
-rw-r--r--gui/src/main/index.ts63
-rw-r--r--gui/src/main/linux-desktop-entry.ts5
-rw-r--r--gui/src/main/linux-split-tunneling.ts3
-rw-r--r--gui/src/main/load-translations.ts6
8 files changed, 71 insertions, 37 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;
}