Catch hook errors in two ways:

- try/catch for catching synchronous errors
- Promise.allSettled will allow for rejected promises without fast-failing other promises
This commit is contained in:
Henrik Giesel 2021-07-19 01:23:41 +02:00
parent 99e3ad7690
commit eb4550d2d5
2 changed files with 18 additions and 4 deletions

View file

@ -27,14 +27,21 @@ export function getTypedAnswer(): string | null {
return typeans?.value ?? null;
}
function _runHook(arr: Array<Callback>): Promise<void[]> {
function _runHook(
arr: Array<Callback>
): Promise<PromiseSettledResult<void | Promise<void>>[]> {
const promises: (Promise<void> | 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<void> = Promise.resolve();

View file

@ -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/*"],