From 127674d8e523708a33baeb3e43b5b282c19d835d Mon Sep 17 00:00:00 2001 From: Michael Peters Date: Sat, 4 Dec 2021 08:40:08 -0600 Subject: [PATCH] even more strict typescript options --- client/webapp/auto-verifier.ts | 4 ++-- client/webapp/elements/events-add-guild.ts | 4 ++-- client/webapp/elements/overlay-add-guild.ts | 6 +++--- client/webapp/elements/require/elements-util.ts | 6 +++--- client/webapp/util.ts | 6 +++--- concurrent-queue/concurrent-queue.ts | 4 ++-- server/server-controller.ts | 16 ++++++++-------- tsconfig.json | 5 +++-- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/client/webapp/auto-verifier.ts b/client/webapp/auto-verifier.ts index 63ab2c4..f881248 100644 --- a/client/webapp/auto-verifier.ts +++ b/client/webapp/auto-verifier.ts @@ -251,10 +251,10 @@ export class AutoVerifier { } } await tryResolveTrustedPromise(); - } catch (e) { + } catch (e: unknown) { this.unverify(); if (!resolved) { - reject(e); + reject(e as Error); resolved = true; } else { console.warn('server request failed after returning cache value (or when already rejected)', e); diff --git a/client/webapp/elements/events-add-guild.ts b/client/webapp/elements/events-add-guild.ts index 8c37518..298ed0d 100644 --- a/client/webapp/elements/events-add-guild.ts +++ b/client/webapp/elements/events-add-guild.ts @@ -53,9 +53,9 @@ export default function bindAddGuildEvents(document: Document, q: Q, ui: UI, gui } let overlayElement = createAddGuildOverlay(document, q, ui, guildsManager, addGuildData as IAddGuildData); document.body.appendChild(overlayElement); - } catch (e) { + } catch (e: unknown) { LOG.error('Unable to parse guild data', e); - let errorOverlayElement = createErrorMessageOverlay(document, 'Unable to parse guild file', e.message); + let errorOverlayElement = createErrorMessageOverlay(document, 'Unable to parse guild file', (e as Error).message); document.body.appendChild(errorOverlayElement); } diff --git a/client/webapp/elements/overlay-add-guild.ts b/client/webapp/elements/overlay-add-guild.ts index 1b4fb10..3ae181b 100644 --- a/client/webapp/elements/overlay-add-guild.ts +++ b/client/webapp/elements/overlay-add-guild.ts @@ -201,9 +201,9 @@ export default function createAddGuildOverlay(document: Document, q: Q, ui: UI, q.$$$(element, '.submit').innerText = 'Registering...'; try { newGuild = await guildsManager.addNewGuild(addGuildData, displayName, avatarBuff); - } catch (e) { - LOG.warn('error adding new guild: ' + e.message, e); // explicitly not printing stack trace here - q.$$$(element, '.error').innerText = e.message; + } catch (e: unknown) { + LOG.warn('error adding new guild: ' + (e as Error).message, e); // explicitly not printing stack trace here + q.$$$(element, '.error').innerText = (e as Error).message; q.$$$(element, '.submit').innerText = 'Try Again'; await ElementsUtil.shakeElement(q.$$$(element, '.submit'), 400); newGuild = null; diff --git a/client/webapp/elements/require/elements-util.ts b/client/webapp/elements/require/elements-util.ts index 272133d..4528f24 100644 --- a/client/webapp/elements/require/elements-util.ts +++ b/client/webapp/elements/require/elements-util.ts @@ -366,9 +366,9 @@ export default class ElementsUtil { if (!resourceId) throw new ShouldNeverHappenError('resourceId is null and we are not using a pre-download'); try { resourceBuff = (await guild.fetchResource(resourceId)).data; - } catch (e) { - LOG.error('Error downloading resource', e); - if (downloadFailFunc) await downloadFailFunc(e); + } catch (e: unknown) { + LOG.error('Error downloading resource', { e }); + if (downloadFailFunc) await downloadFailFunc(e as string); downloading = false; return; } diff --git a/client/webapp/util.ts b/client/webapp/util.ts index f44f0bd..5aff04b 100644 --- a/client/webapp/util.ts +++ b/client/webapp/util.ts @@ -26,11 +26,11 @@ export default class Util { try { await fs.stat(path); return true; - } catch (e) { - if (e.code == 'ENOENT') { + } catch (e: unknown) { + if ((e as any).code == 'ENOENT') { return false; } else { - throw new Error('Error checking if file exists: ' + e.code); + throw new Error('Error checking if file exists: ' + (e as any).code); } } } diff --git a/concurrent-queue/concurrent-queue.ts b/concurrent-queue/concurrent-queue.ts index 01ef354..681d851 100644 --- a/concurrent-queue/concurrent-queue.ts +++ b/concurrent-queue/concurrent-queue.ts @@ -31,8 +31,8 @@ export default class ConcurrentQueue { (async () => { try { taskData.resolve(await taskData.task()); - } catch (e) { - taskData.reject(e); + } catch (e: unknown) { + taskData.reject(e as Error); } this.current -= 1; this._checkQueue(); diff --git a/server/server-controller.ts b/server/server-controller.ts index 7b1f9a3..6555bbc 100644 --- a/server/server-controller.ts +++ b/server/server-controller.ts @@ -107,8 +107,8 @@ function bindEvent( let hasPrivilege: boolean; try { hasPrivilege = await DB.hasPrivilege(identity.guildId, identity.memberId, privilege); - } catch (e) { - throw new EventError('not authorized', e, 'unable to check privilege'); + } catch (e: unknown) { + throw new EventError('not authorized', e as Error, 'unable to check privilege'); } if (!hasPrivilege) { throw new EventError('not authorized'); @@ -122,7 +122,7 @@ function bindEvent( if (e instanceof EventError) { throw e; } else { - throw new EventError(`unable to handle ${name} request`, e); + throw new EventError(`unable to handle ${name} request`, e as Error); } } } catch (e) { @@ -221,9 +221,9 @@ function bindChallengeVerificationEvents(io: socketio.Server, client: socketio.S let memberInfo = await DB.getMemberInfo(identity.publicKey); identity.memberId = memberInfo.member_id; identity.guildId = memberInfo.guild_id; - } catch (e) { + } catch (e: unknown) { // unable to find a member with the specified public key - throw new EventError('unauthorized public key', e); + throw new EventError('unauthorized public key', e as Error); } LOG.debug(`c#${client.id}: challenging for u#${identity.memberId}`); @@ -273,8 +273,8 @@ function bindChallengeVerificationEvents(io: socketio.Server, client: socketio.S let verified: boolean; try { verified = verify.verify(identity.publicKey, signature, 'hex'); - } catch (e) { - throw new EventError('unable to verify signature', e); + } catch (e: unknown) { + throw new EventError('unable to verify signature', e as Error); } if (!verified) { @@ -285,7 +285,7 @@ function bindChallengeVerificationEvents(io: socketio.Server, client: socketio.S await DB.setMemberStatus(identity.guildId, identity.memberId, 'online'); let member = await DB.getMember(identity.guildId, identity.memberId); io.to(identity.guildId).emit('update-member', member); - } catch (e) { + } catch (e: unknown) { LOG.warn('unable to set status for m#' + identity.memberId, e); // not killing here since this should not be a game ender. Most likely, the SQL server is bad though } diff --git a/tsconfig.json b/tsconfig.json index f0dea3d..b9c5156 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,10 +10,11 @@ "noImplicitAny": true, "noPropertyAccessFromIndexSignature": true, "noUncheckedIndexedAccess": true, - "strictFunctionTypes": true, "strictBindCallApply": true, - "strictPropertyInitialization": true, + "strictFunctionTypes": true, "strictNullChecks": true, + "strictPropertyInitialization": true, + "useUnknownInCatchVariables": true, "alwaysStrict": true, "skipLibCheck": true, "outDir": "dist"