mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] lifecyle_hooks: correctly wrap errors in async code
Before this commit, wrapping an error occurring in async code would result in an unhandledpromise exception, because we created another promise, that would be rejected and that we didn't catch.
This commit is contained in:
committed by
Géry Debongnie
parent
d1118455aa
commit
30bc605c84
@@ -264,6 +264,30 @@ describe("errors and promises", () => {
|
||||
expect(error!.message).toBe("Tokenizer error: could not tokenize `{ 'invalid: 5 }`");
|
||||
});
|
||||
|
||||
test("wrapped errors in async code are correctly caught", async () => {
|
||||
class Root extends Component {
|
||||
static template = xml`<div>abc</div>`;
|
||||
setup() {
|
||||
onWillStart(async () => {
|
||||
await Promise.resolve();
|
||||
throw new Error("boom in onWillStart");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
let error: any;
|
||||
try {
|
||||
await mount(Root, fixture, { test: true });
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
expect(error!).toBeDefined();
|
||||
expect(error!.message).toBe(
|
||||
`The following error occurred in onWillStart: "boom in onWillStart"`
|
||||
);
|
||||
await new Promise((r) => setTimeout(r, 0)); // wait for the rejection event to bubble
|
||||
});
|
||||
|
||||
test("an error in willPatch call will reject the render promise", async () => {
|
||||
class Root extends Component {
|
||||
static template = xml`<div><t t-esc="val"/></div>`;
|
||||
|
||||
Reference in New Issue
Block a user