[IMP] mail: improve after event error stack trace
Before this commit the error raised/logged when rejecting the afterEvent promise was imcomplete. This is due to the fact we're creating the error inside the promise itself. In order to get a better stack trace, the error is now declared outside of the promise. Moreover, both `afterNextRender` and `afterEvent` functions were using `console.error` before rejecting the promise. This is also a problem since runbot will show the error printed by `console.error` instead of the one of the test failure. In order to solve this issue, those two `console.error` have been replaced by `console.warn`. closes odoo/odoo#99899 Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
This commit is contained in:
@@ -69,14 +69,12 @@ function getAfterEvent({ messagingBus }) {
|
||||
* @returns {Promise}
|
||||
*/
|
||||
return async function afterEvent({ eventName, func, message, predicate, timeoutDelay = 5000 }) {
|
||||
const error = new Error(message || `Timeout: the event ${eventName} was not triggered.`);
|
||||
// Set up the timeout to reject if the event is not triggered.
|
||||
let timeoutNoEvent;
|
||||
const timeoutProm = new Promise((resolve, reject) => {
|
||||
timeoutNoEvent = setTimeout(() => {
|
||||
let error = message
|
||||
? new Error(message)
|
||||
: new Error(`Timeout: the event ${eventName} was not triggered.`);
|
||||
console.error(error);
|
||||
console.warn(error);
|
||||
reject(error);
|
||||
}, timeoutDelay);
|
||||
});
|
||||
@@ -92,9 +90,12 @@ function getAfterEvent({ messagingBus }) {
|
||||
// promise has been registered to not miss any potential event.
|
||||
const funcRes = func();
|
||||
// Make them race (first to resolve/reject wins).
|
||||
await Promise.race([eventProm, timeoutProm]);
|
||||
clearTimeout(timeoutNoEvent);
|
||||
messagingBus.removeEventListener(eventName, eventHandler);
|
||||
await Promise.race([eventProm, timeoutProm]).finally(() => {
|
||||
// Execute clean up regardless of whether the promise is
|
||||
// rejected or not.
|
||||
clearTimeout(timeoutNoEvent);
|
||||
messagingBus.removeEventListener(eventName, eventHandler);
|
||||
});
|
||||
// If the event is triggered before the end of the async function,
|
||||
// ensure the function finishes its job before returning.
|
||||
return await funcRes;
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
if (runningSchedulers.length) {
|
||||
error = stopError;
|
||||
}
|
||||
console.error(
|
||||
console.warn(
|
||||
error,
|
||||
runningSchedulers.map((s) => [...s.tasks].map((f) => [f, f.node.status])),
|
||||
runningSchedulers
|
||||
|
||||
Reference in New Issue
Block a user