Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the line number of an error when executing code in the sandbox? #18

Open
IamSanjid opened this issue Mar 21, 2023 · 2 comments

Comments

@IamSanjid
Copy link

IamSanjid commented Mar 21, 2023

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.

@IamSanjid IamSanjid changed the title How to handle errors which occurred while executing? How to get the line number of an error when executing code in the sandbox? Mar 21, 2023
@nyariv
Copy link
Owner

nyariv commented Mar 27, 2023

The sandbox currently does not keep track of stack trace, so it provides a code snippet where the issue is.

@IamSanjid
Copy link
Author

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.

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

No branches or pull requests

2 participants