swallow errors in errorCallback in ErrorBoundary

nothing should be able to make ErrorBoundary.try throw
This commit is contained in:
Bruno Windels 2023-01-19 11:37:39 +01:00
parent 2408850678
commit daad19c060

View File

@ -32,18 +32,26 @@ export class ErrorBoundary {
if (result instanceof Promise) {
result = result.catch(err => {
this._error = err;
this.errorCallback(err);
this.reportError(err);
return errorValue;
});
}
return result;
} catch (err) {
this._error = err;
this.errorCallback(err);
this.reportError(err);
return errorValue;
}
}
private reportError(err: Error) {
try {
this.errorCallback(err);
} catch (err) {
console.error("error in ErrorBoundary callback", err);
}
}
get error(): Error | undefined {
return this._error;
}
@ -77,6 +85,15 @@ export function tests() {
}, 0);
assert(emitted);
assert.strictEqual(result, 0);
},
"exception in error callback is swallowed": async assert => {
let emitted = false;
const boundary = new ErrorBoundary(() => { throw new Error("bug in errorCallback"); });
assert.doesNotThrow(() => {
boundary.try(() => {
throw new Error("fail!");
});
});
}
}
}