Closed damianofalcioni closed 6 days ago
What about this? Does it work for your scenario?
const interpreter = new Sval()
try {
interpreter.run('console.error(myObj)')
} catch (err) {
console.error('Caught error')
}
Could you offer a repo or something to reproduce this bug? It seems I can't reproduce it with sval@0.5.2 on node v20.12.2.
when the code is inside an async it is not catch:
import Sval from 'sval';
const interpreter = new Sval();
try {
interpreter.run(`
!async function () {
console.log(myObj);
}();`);
} catch (e) {
console.error('err');
}
Right, that's how async behaves. The async function doesn't run in the current loop, so try-catch can't catch the error synchronously. Try to catch the error inside:
import Sval from 'sval';
const interpreter = new Sval();
interpreter.run(`
!async function () {
try {
console.log(myObj);
} catch (e) {
console.error('err');
}
}();`);
Thanks, that solved the issue
Hi, when the runned code try to access an object that has not been imported it generate a ReferenceError that cannot be catch.
There is a way to handle it? I've seen in the code there is a throwErr option but is not exposed.
Thanks
PS: I'm importing Sval as an ES6 module in Node