mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-22 19:14:52 +01:00
swallow errors in errorCallback in ErrorBoundary
nothing should be able to make ErrorBoundary.try throw
This commit is contained in:
parent
2408850678
commit
daad19c060
@ -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!");
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user