From c6dfab9e6770e41f1cab10ada42aae5a62399928 Mon Sep 17 00:00:00 2001 From: Labhansh Agrawal Date: Mon, 30 Aug 2021 13:37:13 +0000 Subject: [PATCH] Fix type errors due to unknow type in try catch --- app/config/init.ts | 3 ++- app/plugins.ts | 3 ++- app/session.ts | 9 ++++++--- app/utils/cli-install.ts | 5 +++-- cli/api.ts | 3 ++- lib/components/term.tsx | 3 ++- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/app/config/init.ts b/app/config/init.ts index 39a62b51..b9ac181a 100644 --- a/app/config/init.ts +++ b/app/config/init.ts @@ -16,7 +16,8 @@ const _extract = (script?: vm.Script): Record => { const _syntaxValidation = (cfg: string) => { try { return new vm.Script(cfg, {filename: '.hyper.js', displayErrors: true}); - } catch (err) { + } catch (_err) { + const err = _err as {name: string}; notify(`Error loading config: ${err.name}`, `${err}`, {error: err}); } }; diff --git a/app/plugins.ts b/app/plugins.ts index f4cdefbc..f0e418de 100644 --- a/app/plugins.ts +++ b/app/plugins.ts @@ -296,7 +296,8 @@ function requirePlugins(): any[] { console.log(`Plugin ${mod._name} (${mod._version}) loaded.`); return mod; - } catch (err) { + } catch (_err) { + const err = _err as {code: string; message: string}; if (err.code === 'MODULE_NOT_FOUND') { console.warn(`Plugin error while loading "${basename(path_)}" (${path_}): ${err.message}`); } else { diff --git a/app/session.ts b/app/session.ts index dcbcba2c..051f89bb 100644 --- a/app/session.ts +++ b/app/session.ts @@ -154,7 +154,8 @@ export default class Session extends EventEmitter { try { this.pty = spawn(shell, shellArgs, options); - } catch (err) { + } catch (_err) { + const err = _err as {message: string}; if (/is not a function/.test(err.message)) { throw createNodePtyError(); } else { @@ -215,7 +216,8 @@ fallback to default shell config: ${JSON.stringify(defaultShellConfig, undefined if (this.pty) { try { this.pty.resize(cols, rows); - } catch (err) { + } catch (_err) { + const err = _err as {stack: any}; console.error(err.stack); } } else { @@ -227,7 +229,8 @@ fallback to default shell config: ${JSON.stringify(defaultShellConfig, undefined if (this.pty) { try { this.pty.kill(); - } catch (err) { + } catch (_err) { + const err = _err as {stack: any}; console.error('exit error', err.stack); } } else { diff --git a/app/utils/cli-install.ts b/app/utils/cli-install.ts index 7cac74a6..02cc7894 100644 --- a/app/utils/cli-install.ts +++ b/app/utils/cli-install.ts @@ -40,7 +40,8 @@ const addSymlink = async (silent: boolean) => { } } await symlink(cliScriptPath, cliLinkPath); - } catch (err) { + } catch (_err) { + const err = _err as {code: string}; // 'EINVAL' is returned by readlink, // 'EEXIST' is returned by symlink let error = @@ -61,7 +62,7 @@ sudo ln -sf "${cliScriptPath}" "${cliLinkPath}"`, await sudoExec(`ln -sf "${cliScriptPath}" "${cliLinkPath}"`, {name: 'Hyper'}); return; } catch (_error) { - error = _error[0]; + error = (_error as any[])[0]; } } else if (result.response === 1) { clipboard.writeText(`sudo ln -sf "${cliScriptPath}" "${cliLinkPath}"`); diff --git a/cli/api.ts b/cli/api.ts index d99174f5..e595db3a 100644 --- a/cli/api.ts +++ b/cli/api.ts @@ -45,7 +45,8 @@ function memoize any>(fn: T): T { const getFileContents = memoize(() => { try { return fs.readFileSync(fileName, 'utf8'); - } catch (err) { + } catch (_err) { + const err = _err as {code: string}; if (err.code !== 'ENOENT') { // ENOENT === !exists() throw err; diff --git a/lib/components/term.tsx b/lib/components/term.tsx index 9febd372..9bdf5dd0 100644 --- a/lib/components/term.tsx +++ b/lib/components/term.tsx @@ -352,7 +352,8 @@ export default class Term extends React.PureComponent { .forEach((option) => { try { this.term.setOption(option, nextTermOptions[option]); - } catch (e) { + } catch (_e) { + const e = _e as {message: string}; if (/The webgl renderer only works with the webgl char atlas/i.test(e.message)) { // Ignore this because the char atlas will also be changed } else {