quickjs icon indicating copy to clipboard operation
quickjs copied to clipboard

Some errors are not correctly reported during promises

Open didattica-forever opened this issue 4 years ago • 1 comments

I'm quite new to quickjs, while testing (QuickJS version 2021-03-27) I took the following piece of code from MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Using_promises

new Promise((resolve, reject) => {
    console.log('Initial');
    resolve();
})
.then(() => {
    throw new Error('Something failed');
    console.log('Do this');
})
.catch(() => {
    console.error('Do that');
})
.then(() => {
    console.log('Do this, no matter what happened before');
});

the only output I got was Initial it did took me sometime to discover that the statement console.error('Do that'); was the origin because of no support, but qjs did not raise any error.

if console.error is used in the main script qjs correctly stops at TypeError: not a function at (promises.js:43)

The same happens with "use strict" and a variable is set without declaration in the promise.

My feeling is that the error is caught but for some reason qjs is not able to abort nor to signal.

thank you beforehand.

Paolo

didattica-forever avatar Aug 02 '21 06:08 didattica-forever

Use the --unhandled-rejection option. Note there are false positives possible, e.g.

new Promise((accept, reject) => reject('ERROR')).catch(console.log)

will show a warning about a possibly unhandled rejection, since the rejection happens before the handler is attached.

fstirlitz avatar Aug 27 '21 09:08 fstirlitz