From eb4550d2d5e2dd089170a04e1301583ff4afe1f8 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Mon, 19 Jul 2021 01:23:41 +0200 Subject: [PATCH] Catch hook errors in two ways: - try/catch for catching synchronous errors - Promise.allSettled will allow for rejected promises without fast-failing other promises --- ts/reviewer/index.ts | 13 ++++++++++--- ts/tsconfig.json | 9 ++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ts/reviewer/index.ts b/ts/reviewer/index.ts index 0fa0a626a..2da615e82 100644 --- a/ts/reviewer/index.ts +++ b/ts/reviewer/index.ts @@ -27,14 +27,21 @@ export function getTypedAnswer(): string | null { return typeans?.value ?? null; } -function _runHook(arr: Array): Promise { +function _runHook( + arr: Array +): Promise>[]> { const promises: (Promise | void)[] = []; for (let i = 0; i < arr.length; i++) { - promises.push(arr[i]()); + try { + const result = arr[i](); + promises.push(result); + } catch (error) { + console.log("Hook failed: ", error); + } } - return Promise.all(promises); + return Promise.allSettled(promises); } let _updatingQueue: Promise = Promise.resolve(); diff --git a/ts/tsconfig.json b/ts/tsconfig.json index 39ff8565a..91321c08f 100644 --- a/ts/tsconfig.json +++ b/ts/tsconfig.json @@ -3,7 +3,14 @@ "compilerOptions": { "target": "es6", "module": "es6", - "lib": ["es2017", "es2019.array", "es2018.promise", "dom", "dom.iterable"], + "lib": [ + "es2017", + "es2019.array", + "es2018.promise", + "es2020.promise", + "dom", + "dom.iterable" + ], "baseUrl": ".", "paths": { "lib/*": ["../bazel-bin/ts/lib/*"],