SandboxJS
SandboxJS copied to clipboard
How to get the line number of an error when executing code in the sandbox?
const sandbox = new Sandbox();
const code = `function onStart() {
console.log(some_undefined_var);
}
return { onStart: onStart };
`;
const exec = sandbox.compile(code);
const script_context = exec({}).run();
// here an error should occur...
script_context['onStart']();
So I would like to know at which line(maybe?) the error occurred while executing the code in the provided coding string, I think I can get the function name in a way but need some examples of how to approach this.
The sandbox currently does not keep track of stack trace, so it provides a code snippet where the issue is.
The sandbox currently does not keep track of stack trace, so it provides a code snippet where the issue is.
How can I retrieve that code snippet? Normal try-catch doesn't seem to be helping any example would be helpful.