From eb4550d2d5e2dd089170a04e1301583ff4afe1f8 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Mon, 19 Jul 2021 01:23:41 +0200 Subject: [PATCH 1/2] 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/*"], From b3a7a4ac3dfc81600fa1c19bf244d16ede694d87 Mon Sep 17 00:00:00 2001 From: Henrik Giesel Date: Mon, 19 Jul 2021 01:33:58 +0200 Subject: [PATCH 2/2] Use new for-loop --- ts/reviewer/index.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ts/reviewer/index.ts b/ts/reviewer/index.ts index 2da615e82..f95c97507 100644 --- a/ts/reviewer/index.ts +++ b/ts/reviewer/index.ts @@ -28,13 +28,13 @@ export function getTypedAnswer(): string | null { } function _runHook( - arr: Array + hooks: Array ): Promise>[]> { const promises: (Promise | void)[] = []; - for (let i = 0; i < arr.length; i++) { + for (const hook of hooks) { try { - const result = arr[i](); + const result = hook(); promises.push(result); } catch (error) { console.log("Hook failed: ", error);