[IMP] *: use a custom error class for all errors thrown by owl

This commit makes all errors thrown in owl use a custom error class. The
main point of this is to always wrap user-code errors that happen during
the owl lifecycle so that they can be treated uniformly in onError by
checking the cause property, and also allows user code to differenciate
owl errors from non-owl errors reliably at runtime.
This commit is contained in:
Samuel Degueldre
2022-07-18 10:41:50 +02:00
committed by Géry Debongnie
parent 30bc605c84
commit 7786077921
24 changed files with 261 additions and 100 deletions
+6 -4
View File
@@ -1,3 +1,4 @@
import { OwlError } from "../../src/runtime/error_handling";
import {
App,
Component,
@@ -499,7 +500,7 @@ describe("Portal", () => {
</div>`;
state = { error: false };
setup() {
onError((e) => (error = e));
onError(({ cause }) => (error = cause));
}
}
addOutsideDiv(fixture);
@@ -958,14 +959,15 @@ describe("Portal: Props validation", () => {
</t>
</div>`;
}
let error: Error;
let error: OwlError;
try {
await mount(Parent, fixture, { dev: true });
} catch (e) {
error = e as Error;
error = e as OwlError;
}
expect(error!).toBeDefined();
expect(error!.message).toBe(`' ' is not a valid selector`);
expect(error!.cause).toBeDefined();
expect(error!.cause.message).toBe(`' ' is not a valid selector`);
});
test("target must be a valid selector 2", async () => {