mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] component: propagate errors to parent
Before this commit, the error handling process was too naive: once an error occurs in a rendering, owl catches it, looks for a component that implements the catchError method, then calls it. However, in real life, we sometimes need to rethrow that error (or another one) to propagate the error to some parent handler. This error needs to be handled by the closest parent component that implements catchError. This is what this commit implements: it wraps the catchError call in a try/catch, then in case of errors, try to handle it by a parent.
This commit is contained in:
+23
-9
@@ -326,16 +326,30 @@ export class Fiber {
|
||||
|
||||
const qweb = component.env.qweb;
|
||||
let root = component;
|
||||
let canCatch = false;
|
||||
while (component && !(canCatch = !!component.catchError)) {
|
||||
root = component;
|
||||
component = component.__owl__.parent!;
|
||||
}
|
||||
qweb.trigger("error", error);
|
||||
|
||||
if (canCatch) {
|
||||
component.catchError!(error);
|
||||
} else {
|
||||
function handle(error) {
|
||||
let canCatch = false;
|
||||
qweb.trigger("error", error);
|
||||
while (component && !(canCatch = !!component.catchError)) {
|
||||
root = component;
|
||||
component = component.__owl__.parent!;
|
||||
}
|
||||
if (canCatch) {
|
||||
try {
|
||||
component.catchError!(error);
|
||||
} catch (e) {
|
||||
root = component;
|
||||
component = component.__owl__.parent!;
|
||||
return handle(e);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
let isHandled = handle(error);
|
||||
|
||||
if (!isHandled) {
|
||||
// the 3 next lines aim to mark the root fiber as being in error, and
|
||||
// to force it to end, without waiting for its children
|
||||
this.root.counter = 0;
|
||||
|
||||
Reference in New Issue
Block a user