Skip to content

Fix __TS__AsyncAwaiter error handling#1168

Merged
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
dicarlo2:fix_promise_error
Nov 19, 2021
Merged

Fix __TS__AsyncAwaiter error handling#1168
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
dicarlo2:fix_promise_error

Conversation

@dicarlo2
Copy link
Copy Markdown
Contributor

Similar to line 64, this should use errorOrErrorHandler in order to capture the thrown error.

Happy to add tests if you can give me some pointers on how to do so. Here is an example where the current code breaks:

const success = async () => {};
const error = async () => {
  await success();
  throw new Error('Hello World');
}
error().catch((err) => {
  // prints true prior to change in this PR 
  print(err === undefined); 
});

@Perryvw
Copy link
Copy Markdown
Member

Perryvw commented Nov 19, 2021

Thanks, would indeed be nice if you can add a test here: https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/test/unit/builtins/async-await.spec.ts#L297

Since all of this should be able to run synchonously, you can make use of the promiseTestLib log the error which you return from the test, similar to how this test works: https://github.com/TypeScriptToLua/TypeScriptToLua/blob/master/test/unit/builtins/async-await.spec.ts#L50

To save some time you can use npm test async-await to only run the tests in that file

@Perryvw Perryvw merged commit 028e3f5 into TypeScriptToLua:master Nov 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants