quickjs
quickjs copied to clipboard
[error] Errors thrown by asynchronous functions are not handled
Test code
async function gen() {
return undefined_var;
}
gen().then((r) => {
console.log(`r = ${r}`);
});
Run the code with qjs:
$ qjs --module test-async-error.js
Run the code with node:
$ node test-async-error.js
(node:3508) UnhandledPromiseRejectionWarning: ReferenceError: undefined_var is not defined
at gen (/home/absop/Learning/test-async-error.js:3:5)
at Object.<anonymous> (/home/absop/Learning/test-async-error.js:6:1)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
(node:3508) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:3508) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
I think this is the same as https://github.com/quickjs-ng/quickjs/issues/340
I would like to point out that Node's handling of unhandled rejections and exit code depends on the version and the value passed with CLI option --unhandled-rejections. The original issue seems to address an old version that is no longer supported officially. As of Node 16, the default value has been throw (node#41184), and the old behavior is equivalent to it being warn.
--unhandled-rejections is now the default.